From 68fd037ea854c0619d894355d7ae59282168b02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9D=E6=A2=A6=E5=9B=AD?= Date: Mon, 18 Mar 2024 15:45:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81=E7=AE=A1=E7=90=86=E9=A1=B5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/admin.vue | 4 +- pages/admin/product/post/_product_id.vue | 869 +++++++++--------- .../admin/{product/index.vue => products.vue} | 18 +- 3 files changed, 450 insertions(+), 441 deletions(-) rename pages/admin/{product/index.vue => products.vue} (94%) diff --git a/pages/admin.vue b/pages/admin.vue index ca02b03..7fe431e 100644 --- a/pages/admin.vue +++ b/pages/admin.vue @@ -131,8 +131,8 @@ export default { }, { title: '产品管理', - name: 'admin-product', - path: '/admin/product/index', + name: 'admin-products', + path: '/admin/products', icon: 'el-icon-box', closable: true }, diff --git a/pages/admin/product/post/_product_id.vue b/pages/admin/product/post/_product_id.vue index 19b7030..23a2a79 100644 --- a/pages/admin/product/post/_product_id.vue +++ b/pages/admin/product/post/_product_id.vue @@ -1,435 +1,456 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +--> + let product = { + productContent: productContent, + productContentHtml: productContentHtml, + productStatus: 1, + ..._ts.formStore + }; - - - + _ts.$axios[_ts.formStore.idProduct ? '$put' : '$post']('/api/product/post', product).then(function (res) { + if (res) { + if (res.message) { + _ts.$message(res.message); + _ts.doLoading = false; + return false; + } + localStorage.removeItem('product-title'); + localStorage.removeItem('product-tags'); + _ts.contentEditor.setValue(''); + _ts.$set(_ts, 'notificationFlag', false); + _ts.$router.push({ + name: 'admin-products' + }) + } + }) + }, + getTags() { + let _ts = this; + _ts.$axios.$get('/api/tag/tags').then(function (res) { + if (res) { + _ts.$set(_ts, 'list', res); + } + }) + } + }, + beforeRouteLeave(to, from, next) { + let _ts = this; + if (_ts.notificationFlag) { + _ts.$confirm('系统可能不会保存您所做的更改。', '离开此网站?', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + }).then(() => { + next(); + }).catch(() => { + return false + }); + _ts.$store.commit("setActiveMenu", "product-post"); + } else { + next(); + } + }, + beforeDestroy() { + window.onbeforeunload = null; + }, + async mounted() { + window.addEventListener('beforeunload', e => { + e = e || window.event; + if (e) { + e.returnValue = '关闭提示'; + } + return '关闭提示'; + }); + let _ts = this; + _ts.$store.commit('setActiveMenu', 'product-post'); + const responseData = await _ts.$axios.$get('/api/upload/token'); + if (responseData) { + _ts.$set(_ts, 'tokenURL', { + token: responseData.uploadToken || '', + URL: responseData.uploadURL || '', + linkToImageURL: responseData.linkToImageURL || '' + }) + } + console.log('test') + + _ts.getTags(); + Vue.nextTick(() => { + console.log('test') + + let productContent = ''; + if (_ts.$route.params.product_id) { + _ts.$set(_ts, 'isEdit', true); + let product = _ts.product; + _ts.formStore = JSON.parse(JSON.stringify(product)) + console.log(product) + + // _ts.$set(_ts, 'idArticle', product.idArticle); + // _ts.$set(_ts, 'productTitle', product.productTitle); + // _ts.$set(_ts, 'productContent', product.productContent); + // _ts.$set(_ts, 'productStatus', product.productStatus); + // _ts.$set(_ts, 'productTags', (product.tags).split(',')); + // localStorage.setItem("product-title", product.productTitle); + // localStorage.setItem("product-tags", (product.tags).split(',')); + productContent = product.productContent + } else { + _ts.$set(_ts, 'isEdit', false); + } + _ts.contentEditor = _ts._initEditor({ + id: 'contentEditor', + mode: 'both', + height: 480, + placeholder: '', //_ts.$t('inputContent', _ts.$store.state.locale) + resize: false, + value: productContent + }); + }) + } +} + + + diff --git a/pages/admin/product/index.vue b/pages/admin/products.vue similarity index 94% rename from pages/admin/product/index.vue rename to pages/admin/products.vue index 1aea2f5..fcbe73d 100644 --- a/pages/admin/product/index.vue +++ b/pages/admin/products.vue @@ -111,14 +111,6 @@ import {mapState} from 'vuex'; // import VueCropper from "vue-cropper"; -const rules = { - productTitle: [ - {required: true, message: '请输入公司名称', trigger: 'blur'}, - {min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur'} - ], - productDescription: [{required: true, message: '请输入产品描述', trigger: 'blur'}] - -} export default { name: "productsList", middleware: 'auth', @@ -140,9 +132,6 @@ export default { order: 'desc', editVisible: false, formStore: {}, - rules: rules, - cropperVisible: false, - isEdit: false } }, methods: { @@ -225,13 +214,12 @@ export default { if (data) { this.formStore.productImgUrl = data this.formStore.productImgType = 1 - // this.cropperVisible = false } else _ts.$message.error('失败,请重试'); }, handleAdd() { - this.isEdit = false - this.formStore = {} - this.editVisible = true + this.$router.push({ + path: `/admin/product/post/`, + }) } } }