schema中变量动态设置
我想在submit之前,动态设置下 api的headers里面token字段,为啥在handleFormSubmit里面设置无效,应该怎么设置?
import schema2component from "../../utils/schema2component"; import {RouteComponentProps} from "react-router"; import {IMainStore} from "../../stores"; import {inject, observer} from "mobx-react"; import * as React from "react"; import AMisRenderer from "../../components/AMisRenderer";
interface SettleProps extends RouteComponentProps
let token = ''
const schema = { type: 'page', title: '结算管理', body: { type: "crud", api: { "url": "http://127.0.0.1:9193/api/login", "method": "post", "data": { "all": "$$", "token": token, }, "headers": { "token": "34234234242143242343423", }, }, filter: { type: "form", title: "", submitText: "",
controls: [
{
type: "group",
controls: [
{
title: "结算日期",
type: 'fieldSet',
autoFocus: false,
mode: "horizontal",
controls: [
{
type: "datetime",
name: "select",
abel: "日期"
}
],
submitText: null,
actions: []
},
{
title: "渠道来源",
type: 'fieldSet',
mode: "horizontal",
autoFocus: false,
controls: [
{
name: "select3",
type: "chained-select",
label: "渠道",
source: "",
value: "a,b,c,d,e",
options: [
{
label: "极速版",
value: "极速版",
},
{
label: "米读主版",
value: "米读主版"
}
]
}
],
submitText: null,
actions: []
},
{
type: "submit",
label: "查询",
}
]
}
],
},
columns: [
{
name: "month",
label: "结算月份",
},
{
name: "name",
label: "渠道",
},
{
name: "age",
label: "收入",
},
{
name: "gender",
label: "阅读人数",
},
{
name: 'tel',
label: '阅读章数'
},
{
name: 'company',
label: '阅读字数'
},
{
type: "button",
label: "书籍明细",
actionType: "link",
link: "http://127.0.0.1:8888/admin/customer/book?${tel}",
}
]
}
};
@inject("store")
@observer
export default class SettleRoute extends React.Component
handleFormSubmit = (value:any) => {
schema.body.api.data.token = "aaaaaaaaaaaaaaaaaaaaaaa"
// value.token = "aaaaaaaaaaaaaaaaaaaaaaa"
}
render() {
return (
<AMisRenderer
onFinished={this.handleFormSaved}
onSubmit={this.handleFormSubmit}
schema={schema}
/>
);
}
}
// export default schema2component(schema);
api 有发送适配器,另外,headers 配置的时候也可以像配置 data 一下取变量。
好的,多谢