From 724d2dd15bcc21a059ee048464d0a438a5e48e84 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 30 Sep 2020 11:24:20 +0800 Subject: [PATCH] update --- src/services/template.js | 71 ++++++-- src/utils/request.js | 33 +++- src/views/manage_system/template/index.vue | 183 +++++++++----------- src/views/manage_system/template_matrix.vue | 30 ++-- src/views/manage_system/template_mind.vue | 23 +-- 5 files changed, 188 insertions(+), 152 deletions(-) diff --git a/src/services/template.js b/src/services/template.js index 0ca6bc9b..50cac795 100644 --- a/src/services/template.js +++ b/src/services/template.js @@ -1,28 +1,79 @@ import { fetchApi, wrapErrorHint } from '@/utils/request'; -import { firstCharToLowerCase, firstCharToUpperCase } from '@/utils/tool'; +// import { firstCharToLowerCase, firstCharToUpperCase } from '@/utils/tool'; -export async function createTemplate(params) { - return await fetchApi('template/createTemplate', params); -} -export async function queryTemplateList(){ + +export async function queryTemplateList() { return await fetchApi('template/queryTemplateList'); } + + +/** + * 上传xmind文件 + * @param {File} file + * @return {Object} 服务器解析的xmind节点数据 + */ export async function uploadXmind(file) { // const formData = new FormData(); // formData.append('file', file, file.name); - return await fetchApi('template/uploadingXmind', file, { headers: { - 'Content-Type': 'application/octet-stream', - } }); + return await fetchApi('template/uploadingXmind', file, { + headers: { + 'Content-Type': 'application/octet-stream', + } + }); } - +/** + * 创建模板 + * @param {Object} params + */ +export async function createTemplate(params) { + return await fetchApi('template/createTemplate', params); +} +/** + * 模板详情 + * @param {string} templateId + */ export async function queryTemplateById(templateId) { const res = await fetchApi('template/queryTemplateByTemplateId', { id: templateId }); return wrapErrorHint(res); } - +/** + * 查询模板被引用次数 + * @param {string} templateId + */ +export async function queryTemplateQuoteCount(templateId) { + const res = await fetchApi('template/queryTemplateQuoteCount', { id: templateId }); + return res; +} +/** + * 删除模板 + * @param {string} templateId + */ +export async function deleteTemplate(templateId) { + const res = await fetchApi('template/deleteTemplate', { id: templateId }); + return wrapErrorHint(res); +} +/** + * 更新模板 + * @param {Object} params + */ export async function updateTemplate(params) { const res = await fetchApi('template/updateTemplate', params); return wrapErrorHint(res); +} + +/* jsmind节点树接口 */ + +export async function queryTemplateNodeByTemplateId(templateId) { + const res = await fetchApi('template/queryTemplateNodeByTemplateId', { templateId }); + return wrapErrorHint(res); +} + + +/* 文件交换接口 */ + +export async function queryFileExchange(id){ + const res = await fetchApi('template/queryFileExchange', { id }); + return wrapErrorHint(res); } \ No newline at end of file diff --git a/src/utils/request.js b/src/utils/request.js index f4d1b5ca..1ba8e187 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -47,13 +47,34 @@ axios.interceptors.response.use( export async function fetchApi(path, params, config) { - const [method, fullpath] = mapApiPathToFullPath(path); - const res = await (method === 'GET' - ? axios.get(fullpath, { params }, config) - : axios.post(fullpath, params, config) - ); - return res.data; + try { + const res = await (method === 'GET' + ? axios.get(fullpath, { params }, config) + : axios.post(fullpath, params, config) + ); + return res.data; + } catch(e) { + if(e.response && e.response.status) { + switch(e.response.status) { + case 404: + return { + Code: 404, + Msg: '找不到指定的服务', + }; + default: + return { + Code: 503, + Msg: '服务异常,请稍微再试', + }; + } + } + console.error(e); + return { + Code: 503, + Msg: '服务异常,请稍微再试', + }; + } } export function wrapErrorHint(response) { diff --git a/src/views/manage_system/template/index.vue b/src/views/manage_system/template/index.vue index 72588c93..d90f155c 100644 --- a/src/views/manage_system/template/index.vue +++ b/src/views/manage_system/template/index.vue @@ -2239,8 +2239,6 @@ export default { */ modifyTemplate() { var thisApp = this; - - // 验证表单 thisApp.$refs['tempform'].validate(async (valid) => { if (!valid) return; @@ -2259,7 +2257,7 @@ export default { data.Temple.Disable = +data.Temple.Disable; data.Temple.Locked = +data.Temple.Locked; } - console.log(data); + // console.log(data); data.ChildIndustry = [data.IndLevel3, data.IndLevel4] .filter((a) => a) .join(","); @@ -2373,55 +2371,55 @@ export default { /** * 编辑模板 */ - async modifyTemplateOld() { - const currentTemplate = this.currentTemplateData; - debugger; + // async modifyTemplateOld() { + // const currentTemplate = this.currentTemplateData; + // debugger; - // if (this.selectDetailIndustryIndex === "") { - // const dataIndex = this.currentTemp.detailIndustryID; - // this.currentTemp.detailIndustryID = this.listSonIndustry[dataIndex].id; - // this.currentTemp.fullCode = - // this.listSonIndustry[dataIndex].data.fullCode + - // this.currentTemp.customCode; - // } else { - // const dataIndex = this.selectDetailIndustryIndex; - // this.currentTemp.detailIndustryID = this.listDetailIndustry[ - // dataIndex - // ].id; - // this.currentTemp.fullCode = - // this.listDetailIndustry[dataIndex].data.fullCode + - // this.currentTemp.customCode; - // } - // this.currentTemp.listProperty = this.listTempProp; - // var thisApp = this; - // this.$axios({ - // method: "put", - // url: encodeURI(process.env.API_HOST + "Templates/"), - // data: thisApp.currentTemp, - // }) - // .then(function (response) { - // if (response.data.state == 1) { - // thisApp.$notify({ - // title: "恭喜您", - // message: response.data.message, - // type: "success", - // offset: 100, - // duration: 2500, - // }); - // } else { - // thisApp.$notify({ - // title: "温馨提示", - // message: response.data.message, - // type: "success", - // offset: 100, - // duration: 5000, - // }); - // } - // }) - // .catch(function (error) { - // console.log(error); - // }); - }, + // // if (this.selectDetailIndustryIndex === "") { + // // const dataIndex = this.currentTemp.detailIndustryID; + // // this.currentTemp.detailIndustryID = this.listSonIndustry[dataIndex].id; + // // this.currentTemp.fullCode = + // // this.listSonIndustry[dataIndex].data.fullCode + + // // this.currentTemp.customCode; + // // } else { + // // const dataIndex = this.selectDetailIndustryIndex; + // // this.currentTemp.detailIndustryID = this.listDetailIndustry[ + // // dataIndex + // // ].id; + // // this.currentTemp.fullCode = + // // this.listDetailIndustry[dataIndex].data.fullCode + + // // this.currentTemp.customCode; + // // } + // // this.currentTemp.listProperty = this.listTempProp; + // // var thisApp = this; + // // this.$axios({ + // // method: "put", + // // url: encodeURI(process.env.API_HOST + "Templates/"), + // // data: thisApp.currentTemp, + // // }) + // // .then(function (response) { + // // if (response.data.state == 1) { + // // thisApp.$notify({ + // // title: "恭喜您", + // // message: response.data.message, + // // type: "success", + // // offset: 100, + // // duration: 2500, + // // }); + // // } else { + // // thisApp.$notify({ + // // title: "温馨提示", + // // message: response.data.message, + // // type: "success", + // // offset: 100, + // // duration: 5000, + // // }); + // // } + // // }) + // // .catch(function (error) { + // // console.log(error); + // // }); + // }, /** * 重命名文件夹 */ @@ -2684,61 +2682,43 @@ export default { * 删除模板 */ delTemplateClick: function () { - var thisApp = this; + const currentTemplate = this.currentTemplateData; this.$confirm( - "您正在删除 [" + thisApp.currentTemp.tempName + "] 模板是否继续?", + "您正在删除 [" + currentTemplate.Temple.TempName + "] 模板是否继续?", "删除", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning", } - ).then(() => { - this.$axios({ - method: "delete", - url: encodeURI( - process.env.API_HOST + - "Templates/" + - thisApp.currentTemp.templateID + - "/" + - thisApp.currentTemp.tempName + - "/" + - sessionStorage.userId - ), - }) - .then(function (response) { - thisApp.$notify({ - title: "恭喜您", - message: response.data.message, - type: "success", - offset: 100, - duration: 2500, - }); - thisApp.getTemplateData(); - }) - .catch(function (error) { - console.log(error); - }); + ).then(async () => { + const res = await services.deleteTemplate(currentTemplate.Temple.Id); + if( res.Code !== 0) return; + notify.success('删除成功'); + this.getTemplateData(); }); }, /** * 获取思维导图数据 */ - getTemplateMindTree: function () { - var thisApp = this; - this.$axios({ - method: "get", - url: encodeURI( - process.env.API_HOST + "templates/treenodes/" + thisApp.templateID - ), - }) - .then((response) => { - thisApp.listTemplateMindTree = response.data; - }) - .catch((error) => { - console.log(error); - }); - }, + // async getTemplateMindTree() { + // debugger; + // const templateId = this.templateID; + // const res = await services.queryTemplateNodeByTemplateId(templateId); + // this.listTemplateMindTree = res.Data || []; + // // this.$axios({ + // // method: "get", + // // url: encodeURI( + // // process.env.API_HOST + "templates/treenodes/" + thisApp.templateID + // // ), + // // }) + // // .then((response) => { + // // thisApp.listTemplateMindTree = response.data; + // // }) + // // .catch((error) => { + // // console.log(error); + // // }); + // }, //导入Xmind模板的dialog importXmind: function () { this.isImportDialog = true; @@ -3414,7 +3394,7 @@ export default { name: this.templateName, id: this.templateID, data: this.treeMenuClickData, - }, + } }); }, backmodlemain: function () { @@ -3461,21 +3441,24 @@ export default { * 查看样板文件 */ toNodeFile: function () { - debugger; - var templateId = this.currentTemp.templateID; + const currentTemplateData = this.currentTemplateData; this.$router.push({ name: "system_template_file", params: { - id: templateId, - data: this.currentTemp, + id: currentTemplateData.Temple.Id, + data: currentTemplateData.Temple, }, }); }, /*---------- ----------*/ async getTemplateDetail(templateId) { - const res = await services.queryTemplateById(templateId); + const [res, countRes] = await Promise.all([ + services.queryTemplateById(templateId), + services.queryTemplateQuoteCount(templateId), + ]); const mapIndIdToIndNode = this.mapIndIdToIndNode; + this.nowCount = countRes.Data || 0; if (res.Code !== 0) return; const { propertys, template } = res.Data; // this.currentTemp = template; diff --git a/src/views/manage_system/template_matrix.vue b/src/views/manage_system/template_matrix.vue index 991d7eb8..b4d13eb8 100644 --- a/src/views/manage_system/template_matrix.vue +++ b/src/views/manage_system/template_matrix.vue @@ -129,10 +129,9 @@