diff --git a/admin/src/views/exam/form.vue b/admin/src/views/exam/form.vue index d9079124..eb86a8a9 100644 --- a/admin/src/views/exam/form.vue +++ b/admin/src/views/exam/form.vue @@ -1,58 +1,38 @@ @@ -74,87 +54,36 @@ export default { token: localGet('token') || '', id: id, defaultCate: '', - goodForm: { - goodsName: '', - goodsIntro: '', - originalPrice: '', - sellingPrice: '', - stockNum: '', - goodsSellStatus: '0', - goodsCoverImg: '', - tag: '' + formData: { + name: '', + description: '', + begin: '', + end: '', + requires: {}, + filters: {}, + status: '', }, rules: { goodsName: [ - { required: 'true', message: '请填写商品名称', trigger: ['change'] } + { required: 'true', } ], originalPrice: [ - { required: 'true', message: '请填写商品价格', trigger: ['change'] } + { required: 'true', } ], sellingPrice: [ - { required: 'true', message: '请填写商品售价', trigger: ['change'] } + { required: 'true',} ], stockNum: [ - { required: 'true', message: '请填写商品库存', trigger: ['change'] } + { required: 'true', } ], }, }) let instance onMounted(() => { - instance = new WangEditor(editor.value) - instance.config.showLinkImg = false - instance.config.showLinkImgAlt = false - instance.config.showLinkImgHref = false - instance.config.uploadImgMaxSize = 2 * 1024 * 1024 // 2M - instance.config.uploadFileName = 'file' - instance.config.uploadImgHeaders = { - token: state.token - } - // 图片返回格式不同,需要自定义返回格式 - instance.config.uploadImgHooks = { - // 图片上传并返回了结果,想要自己把图片插入到编辑器中 - // 例如服务器端返回的不是 { errno: 0, data: [...] } 这种格式,可使用 customInsert - customInsert: function(insertImgFn, result) { - console.log('result', result) - // result 即服务端返回的接口 - // insertImgFn 可把图片插入到编辑器,传入图片 src ,执行函数即可 - if (result.data && result.data.length) { - result.data.forEach(item => insertImgFn(item)) - } - } - } - instance.config.uploadImgServer = uploadImgsServer - Object.assign(instance.config, { - onchange() { - console.log('change') - }, - }) - instance.create() - if (id) { - axios.get(`/goods/${id}`).then(res => { - const { goods, firstCategory, secondCategory, thirdCategory } = res - state.goodForm = { - goodsName: goods.goodsName, - goodsIntro: goods.goodsIntro, - originalPrice: goods.originalPrice, - sellingPrice: goods.sellingPrice, - stockNum: goods.stockNum, - goodsSellStatus: String(goods.goodsSellStatus), - goodsCoverImg: proxy.$filters.prefix(goods.goodsCoverImg), - tag: goods.tag - } - state.categoryId = goods.goodsCategoryId - state.defaultCate = `${firstCategory.categoryName}/${secondCategory.categoryName}/${thirdCategory.categoryName}` - if (instance) { - // 初始化商品详情 html - instance.txt.html(goods.goodsDetailContent) - } - }) - } + }) onBeforeUnmount(() => { - instance.destroy() - instance = null + }) const submitAdd = () => { goodRef.value.validate((vaild) => { @@ -163,15 +92,15 @@ export default { let httpOption = axios.post let params = { goodsCategoryId: state.categoryId, - goodsCoverImg: state.goodForm.goodsCoverImg, + goodsCoverImg: state.formData.goodsCoverImg, goodsDetailContent: instance.txt.html(), - goodsIntro: state.goodForm.goodsIntro, - goodsName: state.goodForm.goodsName, - goodsSellStatus: state.goodForm.goodsSellStatus, - originalPrice: state.goodForm.originalPrice, - sellingPrice: state.goodForm.sellingPrice, - stockNum: state.goodForm.stockNum, - tag: state.goodForm.tag + goodsIntro: state.formData.goodsIntro, + goodsName: state.formData.goodsName, + goodsSellStatus: state.formData.goodsSellStatus, + originalPrice: state.formData.originalPrice, + sellingPrice: state.formData.sellingPrice, + stockNum: state.formData.stockNum, + tag: state.formData.tag } if (hasEmoji(params.goodsIntro) || hasEmoji(params.goodsName) || hasEmoji(params.tag) || hasEmoji(params.goodsDetailContent)) { ElMessage.error('不要输入表情包,再输入就打死你个龟孙儿~') @@ -198,7 +127,7 @@ export default { } } const handleUrlSuccess = (val) => { - state.goodForm.goodsCoverImg = val.data || '' + state.formData.goodsCoverImg = val.data || '' } const handleChangeCate = (val) => { state.categoryId = val[2] || 0 @@ -216,24 +145,5 @@ export default {