import Magix from 'magix' import * as View from '../../../view' Magix.applyStyle('@./create-project.less') export default View.extend({ tmpl: '@create-project.html', init (options) { this.options = options }, render () { const { projectInfo, insightId, projectName } = this.options let name = '' if (projectInfo) { name = projectInfo.name + '_副本' // 有projectInfo代表是复制进来的 } else if (projectName) { name = projectName // 编辑时带的名称 } this.updater.digest({ insightId, name, projectInfo }) }, 'cancel' (e) { this.options.dialog.close() }, async 'confirm' (e) { if (!this.isValid()) { return } const { insightId, name, projectInfo } = this.updater.get() const { config } = this.options this.updater.digest({ loading: true }); // 精简下config // baseCrowdExpression里的表达式在后端保存有问题 ['compareCrowd', 'currentCrowd'].forEach(key => { if (config[key]) { delete config[key].baseCrowdExpression delete config[key].userExpression delete config[key].garudaExpression } }) try { let models if (insightId && !projectInfo) { models = [{ name: 'api_analysis_plan_$id_put', pathParams: [insightId], params: { name, frontSettings: JSON.stringify(config) }, isJson: true }] } else { const frontSettings = config ? JSON.stringify(config) : projectInfo.frontSettings models = [{ name: 'api_analysis_plan_post', params: { name, frontSettings }, isJson: true }] } const [model] = await this.fetch(models) const msg = insightId && !projectInfo ? '恭喜,洞察更新成功' : '恭喜,洞察创建成功' this.alert('提示', msg, () => { this.options.dialog.close() if (this.options.callback) { this.options.callback() } }) // let data = model.get('data') // return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } this.updater.digest({ loading: false }) } })