Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
updatePreview(data) {
ams.resources.previewRes.fields.edit = this.copy(data);
ams.resources.previewRes.fields.edit.ctx = 'edit';
ams.resources.previewRes.fields.value = {
type: 'text',
label: '字段值',
ctx: 'view'
};
const viewData = this.copy(data);
let defaultData = viewData.default;
// 三个特殊字段的需要特殊处理
if (viewData.type === 'object' && viewData.fields) {
let newDefaultData = {};
Object.keys(viewData.fields).forEach(item => {
viewData.fields[item].ctx = 'view';
newDefaultData[item] = viewData.fields[item].default;
});
if (!defaultData) {
updatePreview(data) {
ams.resources.previewRes.fields.edit = this.copy(data);
ams.resources.previewRes.fields.edit.ctx = 'edit';
ams.resources.previewRes.fields.value = {
type: 'text',
label: '字段值',
ctx: 'view'
};
const viewData = this.copy(data);
let defaultData = viewData.default;
// 三个特殊字段的需要特殊处理
if (viewData.type === 'object' && viewData.fields) {
let newDefaultData = {};
Object.keys(viewData.fields).forEach(item => {
viewData.fields[item].ctx = 'view';
newDefaultData[item] = viewData.fields[item].default;
});
if (!defaultData) {
defaultData = newDefaultData;
}
params.data[this.field.props['idKey']] = item;
params.data[this.field.props['nameKey']] = item;
params.data[this.field.props['subNameKey']] = item;
}
} else {
params.params = {
// page: 1,
// pageSize: 20
};
if (item) {
params.params[this.field.props['idKey']] = item;
params.params[this.field.props['nameKey']] = item;
params.params[this.field.props['subNameKey']] = item;
}
}
const resource = ams.resources[ams.blocks[this.name].resource];
if (typeof props.withCredentials !== 'undefined') {
params.withCredentials = props.withCredentials;
} else if (typeof resource.api.withCredentials !== 'undefined') {
params.withCredentials = resource.api.withCredentials;
}
const res = await ams.request(params);
const successCode = typeof props.successCode === 'number' ? props.successCode : resource.api.successCode;
// 默认successCode
if (
res.data &&
res.data.code === successCode &&
res.data.data &&
res.data.data.list
) {
return res.data.data.list;
}