From 34588a514cee454fcacb0c5fc03188e3e5c6ca23 Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 20 Mar 2024 21:43:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(components):=20=E4=BA=A7=E5=93=81=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=BB=B4=E6=8A=A4=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/admin/product/post/_product_id.vue | 182 +++++++++++++---------- pages/admin/products.vue | 70 +++------ 2 files changed, 122 insertions(+), 130 deletions(-) diff --git a/pages/admin/product/post/_product_id.vue b/pages/admin/product/post/_product_id.vue index 23a2a79..bfe7da0 100644 --- a/pages/admin/product/post/_product_id.vue +++ b/pages/admin/product/post/_product_id.vue @@ -1,51 +1,66 @@ @@ -84,20 +99,7 @@ export default { computed: { ...mapState({ product: state => state.product.detail.data - }), - // hasPermissions() { - // let account = this.$store.state.auth.user?.nickname; - // if (account) { - // if (this.$route.params.product_id) { - // if (account === this.product.productAuthor.userNickname) { - // return true; - // } - // } else { - // return true; - // } - // } - // return this.$auth.hasScope('blog_admin') || this.$auth.hasScope('admin'); - // } + }) }, data() { return { @@ -107,22 +109,18 @@ export default { linkToImageURL: '', token: '' }, - formStore: { - idArticle: 0, + productInfo: { + idProduct: 0, productTitle: '', productContent: '', productType: 0, tags: '', - productStatus: '0', + status: 0, productPrice: 0, + productImgUrl: '', productImgType: 0 }, - idArticle: 0, - productTitle: '', - productContent: '', - productType: 0, productTags: [], - productStatus: '0', options: [], list: [], loading: false, @@ -134,9 +132,9 @@ export default { } }, methods: { - updateUser(data) { - this.formStore.productImgUrl = data - this.formStore.productImgType = 1 + updateProductImgUrl(data) { + this.productInfo.productImgUrl = data + this.productInfo.productImgType = '1' this.cropperVisible = false }, _initEditor(data) { @@ -268,10 +266,10 @@ export default { this.options = []; } }, - deleteArticle() { + deleteProduct() { let _ts = this; _ts.doLoading = true; - this.$confirm('确定删除吗?', '提示', { + this.$confirm('确定下架吗?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' @@ -295,24 +293,27 @@ export default { }); }, - async postArticle() { + async postProduct() { let _ts = this; _ts.doLoading = true; let productContent = _ts.contentEditor.getValue(); let productContentHtml = await _ts.contentEditor.getHTML(); - if (!(_ts.formStore.productTitle && productContent)) { + if (!(_ts.productInfo.productTitle && productContent)) { _ts.$message("标题/正文不能为空!"); _ts.doLoading = false; return false; } let product = { + idProduct: _ts.productInfo.idProduct, + productTitle: _ts.productInfo.productTitle, + productPrice: _ts.productInfo.productPrice, + productImgType: _ts.productInfo.productImgType || '0', + productImgUrl: _ts.productInfo.productImgUrl, + tags: _ts.productTags.join(','), productContent: productContent, productContentHtml: productContentHtml, - productStatus: 0, - ..._ts.formStore - }; - _ts.$axios[_ts.formStore.idProduct ? '$put' : '$post']('/api/product/post', product).then(function (res) { + _ts.$axios[_ts.productInfo.idProduct ? '$put' : '$post']('/api/product/post', product).then(function (res) { if (res) { if (res.message) { _ts.$message(res.message); @@ -331,13 +332,13 @@ export default { }) }, - async saveArticle() { + async saveProduct() { let _ts = this; _ts.doLoading = true; let id = _ts.$route.params.product_id; let productContent = _ts.contentEditor.getValue(); let productContentHtml = await _ts.contentEditor.getHTML(); - if (!(_ts.formStore.productTitle && productContent)) { + if (!(_ts.productInfo.productTitle && productContent)) { _ts.$message("标题/正文不能为空!"); _ts.doLoading = false; return false; @@ -347,10 +348,10 @@ export default { productContent: productContent, productContentHtml: productContentHtml, productStatus: 1, - ..._ts.formStore + ..._ts.productInfo }; - _ts.$axios[_ts.formStore.idProduct ? '$put' : '$post']('/api/product/post', product).then(function (res) { + _ts.$axios[_ts.productInfo.idProduct ? '$put' : '$post']('/api/product/post', product).then(function (res) { if (res) { if (res.message) { _ts.$message(res.message); @@ -374,6 +375,43 @@ export default { _ts.$set(_ts, 'list', res); } }) + }, + updateStatus() { + let _ts = this; + let product = _ts.productInfo + let title, status; + if (product.status === 0) { + title = '下架'; + status = 1; + } else { + title = '上架'; + status = 0; + } + _ts.$confirm('确定' + title + '产品 ' + product.productTitle + '?', '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + }).then(() => { + _ts.$axios.$patch('/api/admin/product/update-status', { + idProduct: product.idProduct, + status: status + }).then(function (res) { + if (res && res.message) { + _ts.$message.error(res.message); + } else { + _ts.$message({ + type: 'success', + message: title + '成功!' + }); + } + }); + }).catch(() => { + _ts.$message({ + type: 'info', + message: '已取消' + }); + }); + } }, beforeRouteLeave(to, from, next) { @@ -388,7 +426,7 @@ export default { }).catch(() => { return false }); - _ts.$store.commit("setActiveMenu", "product-post"); + _ts.$store.commit("setActiveMenu", "admin-product-post-product_id"); } else { next(); } @@ -405,7 +443,7 @@ export default { return '关闭提示'; }); let _ts = this; - _ts.$store.commit('setActiveMenu', 'product-post'); + _ts.$store.commit('setActiveMenu', 'admin-product-post-product_id'); const responseData = await _ts.$axios.$get('/api/upload/token'); if (responseData) { _ts.$set(_ts, 'tokenURL', { @@ -414,27 +452,17 @@ export default { 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(',')); + _ts.productInfo = JSON.parse(JSON.stringify(product)) productContent = product.productContent + let productTags = product.tags?.split(','); + _ts.$set(_ts, 'productTags', productTags || []); } else { _ts.$set(_ts, 'isEdit', false); } diff --git a/pages/admin/products.vue b/pages/admin/products.vue index fcbe73d..f0933fc 100644 --- a/pages/admin/products.vue +++ b/pages/admin/products.vue @@ -42,20 +42,33 @@ width="180" prop="createdTime"> + + +