diff --git a/src/api/platform/article.js b/src/api/platform/article.js index b3aa16e..1d74a49 100644 --- a/src/api/platform/article.js +++ b/src/api/platform/article.js @@ -8,20 +8,34 @@ export function add(data) { }) } -export function del(ids) { +export function del(id) { return request({ - url: 'api/article', + url: `aerocraftAdminApi/cpArticle/${id}`, method: 'delete', - data: ids }) } export function edit(data) { return request({ - url: 'api/article', + url: 'aerocraftAdminApi/cpArticle', method: 'put', data }) } -export default { add, edit, del } +export function single(id) { + return request({ + url: `aerocraftAdminApi/cpArticle/${id}`, + method: 'get', + }) +} + +export function text(id) { + return request({ + url: `aerocraftAdminApi/cpText/${id}`, + method: 'get', + }) +} + + +export default { add, edit, del, single, text } diff --git a/src/api/platform/label.js b/src/api/platform/label.js index 12612fa..3a84f1c 100644 --- a/src/api/platform/label.js +++ b/src/api/platform/label.js @@ -1,9 +1,10 @@ import request from '@/utils/request' -export function tree(moduleId) { +export function list(moduleId) { return request({ - url: `aerocraftAdminApi/cpLabel/tree/${moduleId}`, + url: `aerocraftAdminApi/cpLabel/all`, method: 'get', + parems: { moduleId } }) } @@ -30,4 +31,4 @@ export function edit(data) { }) } -export default { tree, add, edit, del } +export default { list, add, edit, del } diff --git a/src/components/WangEditor/index.vue b/src/components/WangEditor/index.vue index e81eae3..99b579f 100644 --- a/src/components/WangEditor/index.vue +++ b/src/components/WangEditor/index.vue @@ -7,7 +7,7 @@ :default-config="toolbarConfig" :mode="editMode" /> -
+
{ export const loadMenus = (next, to) => { buildMenus().then(res => { - // res[0].children.push({ - // component: 'system/area/index', - // hidden: false, - // name: 'Area', - // path: 'area', - // meta: { title: '区域管理', icon: 'tree-table', noCache: true } - // }) const sdata = JSON.parse(JSON.stringify(res)) const rdata = JSON.parse(JSON.stringify(res)) const sidebarRoutes = filterAsyncRouter(sdata) diff --git a/src/router/routers.js b/src/router/routers.js index ef5d1e5..c544693 100644 --- a/src/router/routers.js +++ b/src/router/routers.js @@ -79,6 +79,11 @@ export const constantRouterMap = [ }, ] }, + { + path: '/article/content', + component: (resolve) => require(['@/views/platform/article/content'], resolve), + hidden: true + }, ] export default new Router({ diff --git a/src/views/platform/article/add.vue b/src/views/platform/article/add.vue index 27c85d0..a5037c7 100644 --- a/src/views/platform/article/add.vue +++ b/src/views/platform/article/add.vue @@ -86,6 +86,7 @@ import { all } from '@/api/platform/module' import { tree } from '@/api/platform/label' import { upload } from '@/utils/upload' import { mapGetters } from 'vuex' +import { single } from '@/api/platform/article' export default { name: 'ArticleAdd', name: 'ArticleEdit', @@ -134,7 +135,6 @@ export default { text: { required: true, trigger: 'blur', validator: validText }, fileArray: { required: true, message: '请上传封面图', trigger: 'change' }, }, - coverFile: {}, coverHide: false, dialogImageUrl: '', dialogVisible: false, @@ -149,8 +149,8 @@ export default { ]) }, created(){ - const { moduleName, labelName, id } = this.$route.query; - if(moduleName && labelName && !this.isAdd) { + const { id } = this.$route.query; + if(id && !this.isAdd) { this.getArticleDetailById(id); } this.getModules(); @@ -159,18 +159,33 @@ export default { // 封面图片更改 handleUploadChange(uploadFile, uploadFiles) { if(uploadFile.raw.type.includes('image')){ - const file = uploadFile.raw; - this.coverFile = file; - this.coverHide = true; - this.form.fileArray = uploadFiles; + try { + this.loading = true; + upload(this.imagesUploadApi, uploadFile.raw).then(res => { + if(res.status === 200){ + const data = res.data; + const url = '/file/图片/' + data.newFileName; + this.form.photo = url; + this.form.fileArray = [this.baseApi+url]; + this.coverHide = true; + }else{ + this.$message.error('图片上传失败!'); + return; + } + }); + } catch (error) { + this.$message.error('图片上传失败!'); + }finally{ + this.loading = false; + } }else{ this.$message.error('请上传图片文件!'); + uploadFiles.pop(); this.$refs['uploadRef'].clearFiles(); } }, // 封面删除 handleRemove(file) { - this.coverFile = {}; this.form.fileArray = []; this.$refs['uploadRef'].clearFiles(); this.coverHide = false; @@ -201,37 +216,24 @@ export default { this.form.cplabelId = val ? event.currentTarget.dataset.op : ''; }, // 获取文章详情-根据id - async getArticleDetailById(id){ + getArticleDetailById(id){ try { this.loading = true; - // let res = await artApi.getArticleDetail(id); - // if(res?.success) { - // state.data = res.data; - // // 下面这里处理一下,因为后端返回的是0和1,而前端需要的是true和false,到时候提交的时候再转换回来 - // state.data.top = state.data.top === 1; - // state.data.moduleName = moduleName; - // state.data.labelName = labelName; - // state.data.textid = state.data.id; - // if(state.data.photo){ - // const never = [{name:state.data.title,url:viteUrl+state.data.photo}]; - // state.fileArray = never; - // state.coverHide = true; - // } - // } - const { moduleName, labelName } = this.$route.query; - this.form = { - moduleName: moduleName, - labelName: labelName, - title: '测试标题', - articleType: 0, - photo: 'https://huyun120.cn/fd/health/img/%E7%BB%84%20319@2x.f0767b46.png', - text: '测试内容', - top: false, - fileArray:[{name:'测试标题',url:'https://huyun120.cn/fd/health/img/%E7%BB%84%20319@2x.f0767b46.png'}] - }; - this.coverHide = true; + single(id).then(res => { + if(res){ + res.top = res.top ? true : false; + this.form = res; + if(res.photo) { + this.coverHide = true; + this.form.photo = res.photo; + this.form.fileArray = [{url: this.baseApi+this.form.photo}] + } + }else{ + this.$message.error('文章获取失败!'); + } + }) } catch (error) { - this.$message.error('获取文章详情失败'); + this.$message.error('文章获取失败!'); } finally { this.loading = false; } @@ -244,30 +246,24 @@ export default { // 保存 onSubmitForm(){ console.log(this.form); - this.$refs['articleFormRef'].validate(async(valid) => { - if (valid) { - const articleForm = {...this.form}; - articleForm.top = articleForm.top ? 1 : 0; - upload(this.imagesUploadApi, articleForm.fileArray[0].raw).then(res => { - if(res.status === 200){ - const data = res.data; - const url = this.baseApi+'/file/图片/' + data.newFileName; - articleForm.photo = url; - delete articleForm.fileArray; - const ft = this.isAdd? add : edit; - ft(articleForm).then(res => { - this.$message.success(`文章${this.isAdd?'添加':'编辑'}成功!`); - this.cancel(); - }) - }else{ - this.$message.error('新增文章失败'); - return; - } - }); - }else{ - this.$message.error('请完善信息!'); - } - }) + try { + this.$refs['articleFormRef'].validate(async(valid) => { + if (valid) { + const articleForm = {...this.form}; + articleForm.top = articleForm.top ? 1 : 0; + delete articleForm.fileArray; + const ft = this.isAdd? add : edit; + ft(articleForm).then(res => { + this.$message.success(`文章${this.isAdd?'添加':'编辑'}成功!`); + this.cancel(); + }) + }else{ + this.$message.error('请完善信息!'); + } + }) + } catch (error) { + this.$message.error('处理失败!'); + } }, } } diff --git a/src/views/platform/article/content.vue b/src/views/platform/article/content.vue new file mode 100644 index 0000000..692be42 --- /dev/null +++ b/src/views/platform/article/content.vue @@ -0,0 +1,37 @@ + + \ No newline at end of file diff --git a/src/views/platform/article/detail.vue b/src/views/platform/article/detail.vue index 2e9562e..a4c7d1b 100644 --- a/src/views/platform/article/detail.vue +++ b/src/views/platform/article/detail.vue @@ -7,9 +7,9 @@ @@ -29,7 +29,7 @@ - + 图文 @@ -41,12 +41,12 @@ - {{ data.view }} + {{ data.view || 0 }} - {{ data.createtime }} + {{ data.createTime }} @@ -67,6 +67,8 @@ diff --git a/src/views/platform/article/index.vue b/src/views/platform/article/index.vue index 72be241..605c678 100644 --- a/src/views/platform/article/index.vue +++ b/src/views/platform/article/index.vue @@ -25,7 +25,8 @@ - +