import Magix from 'magix' import * as View from '../../../../view' const Sub = require('dmp-new/gallery/mx-table/sub') Magix.applyStyle('@./single-item-analyse-task.less') const statusMap = { '-2': '状态未知', '-1': '运行失败', 0: '运行成功', 1: '运行中', 2: '任务已提交', 3: '任务已取消', 4: '任务已过期' } export default View.extend({ mixins: [Sub], tmpl: '@single-item-analyse-task.html', init(options) { this.options = options this.observeLocation(['page', 'pageSize']) }, async render() { const loc = Magix.Router.parse() const page = loc.get('page') || 1 const pageSize = loc.get('pageSize') || 15 this.updater.set({ statusMap, page, pageSize }) this.updater.digest({ loading: true }) const tasks = await this.getTasks() // tasks.taskList = [] const quota = await this.getQuota() this.updater.digest({ loading: false, quota, tasks, total: tasks.pager.total }) }, async getQuota() { try { const models = [ { name: 'api_scenario_cluster_getUsedQuota_get' } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, async getTasks() { try { const { page, pageSize } = this.updater.get() const params = { page, pageSize } const models = [ { name: 'api_scenario_cluster_list_get', params // timeout: 100 } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data } catch (error) { if (error.msg.includes('timeout')) { this.alert('温馨提示', '系统资源拥挤,请稍候再试...') } else { this.alert('错误提示', error.msg || error.message || error) } } }, 'deleteTask'(e) { const { kmeansTaskId } = e.params const loc = Magix.Router.parse() this.confirm({ title: '提示', content: '确定要删除吗?', enterCallback: async () => { try { const params = { kmeansTaskId } const models = [ { name: 'api_scenario_cluster_delete_post', params, isJson: true } ] const [model] = await this.fetch(models) this.alert('提示', '分析任务删除成功', null, { mask: true }) if (loc.get('page') != '1') { Magix.Router.to({ page: 1 }) } else { this.render() } } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } } }) }, 'rerunTask'(e) { const { kmeansTaskId } = e.params this.confirm({ mask: true, title: '提示', content: '确定要重跑该任务吗?', enterCallback: async () => { try { const params = { kmeansTaskId } const models = [ { name: 'api_scenario_cluster_reRun_post', params, isJson: true } ] const [model] = await this.fetch(models) this.alert('提示', '分析任务开始重跑', null, { mask: true }) this.render() // let data = model.get('data') // return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } } }) }, 'createTask'(e) { const viewPath = '@./create-analyse-task' const viewOptions = { srcWeb: '1', callback: () => { this.render() } } const dialogOptions = { width: 740, header: { tip: '基于单品/单品组历史行为人群进行智能聚类,提供子群显著特征分析,支持人群智能扩展。', title: '创建单品分析任务' } } this.mxModal(viewPath, viewOptions, dialogOptions) }, 'changePage'(e) { Magix.Router.to({ page: e.page, pageSize: e.size }) } })