diff --git a/admin/src/utils/api.js b/admin/src/utils/api.js index 6776db34..effbb6bf 100644 --- a/admin/src/utils/api.js +++ b/admin/src/utils/api.js @@ -36,6 +36,9 @@ const api = { listExam: (params = {}) => { return axios.get('exam', {params: params}); }, + listExamIndex: (params = {}) => { + return axios.get('exam-index', {params: params}); + }, storeExam: (params = {}) => { return axios.post('exam', params); }, diff --git a/admin/src/views/exam/form.vue b/admin/src/views/exam/form.vue index eb86a8a9..db47bb1a 100644 --- a/admin/src/views/exam/form.vue +++ b/admin/src/views/exam/form.vue @@ -2,33 +2,74 @@
- - - + + + - - + + - - - - - - - - - - - - - + + - 启用 - 禁用 + Enabled + Disabled + + + + + + + + + + + + {{item}} + + + + + + + + + + + + - {{ id ? '立即修改' : '立即创建' }} + Submit @@ -41,81 +82,72 @@ import { reactive, ref, toRefs, onMounted, onBeforeUnmount, getCurrentInstance } import { ElMessage } from 'element-plus' import { useRoute, useRouter } from 'vue-router' import { localGet } from '../../utils' +import api from "../../utils/api"; + export default { - name: 'AddGood', + name: 'ExamForm', setup() { const { proxy } = getCurrentInstance() console.log('proxy', proxy) - const goodRef = ref(null) + const formRef = ref(null) const route = useRoute() const router = useRouter() const { id } = route.query const state = reactive({ token: localGet('token') || '', id: id, - defaultCate: '', + allClasses: [], formData: { name: '', description: '', begin: '', end: '', - requires: {}, - filters: {}, + indexes: [], + filters: { + classes: [], + register_time_range: [] + }, status: '', }, rules: { - goodsName: [ + name: [ { required: 'true', } ], - originalPrice: [ + indexes: [ { required: 'true', } ], - sellingPrice: [ + status: [ { required: 'true',} ], - stockNum: [ - { required: 'true', } - ], }, }) - let instance onMounted(() => { - + listAllClass() + listAllIndex() + if (id) { + let res = api.getExam(id) + // state.formData = res.data + } else { + let res = api.listExamIndex() + state.formData.indexes = res.data + } }) onBeforeUnmount(() => { }) const submitAdd = () => { - goodRef.value.validate((vaild) => { + formRef.value.validate(async (vaild) => { if (vaild) { - // 默认新增用 post 方法 - let httpOption = axios.post - let params = { - goodsCategoryId: state.categoryId, - goodsCoverImg: state.formData.goodsCoverImg, - goodsDetailContent: instance.txt.html(), - 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 + let params = state.formData; + if (params.begin) { + params.begin = dayjs(params.begin).format('YYYY-MM-DD HH:mm:ss') } - if (hasEmoji(params.goodsIntro) || hasEmoji(params.goodsName) || hasEmoji(params.tag) || hasEmoji(params.goodsDetailContent)) { - ElMessage.error('不要输入表情包,再输入就打死你个龟孙儿~') - return + if (params.end) { + params.end = dayjs(params.end).format('YYYY-MM-DD HH:mm:ss') } - console.log('params', params) - if (id) { - params.goodsId = id - // 修改商品使用 put 方法 - httpOption = axios.put - } - httpOption('/goods', params).then(() => { - ElMessage.success(id ? '修改成功' : '添加成功') - router.push({ path: '/good' }) - }) + console.log(params) + let res = await api.storeExam(params) + console.log(res) } }) } @@ -132,13 +164,26 @@ export default { const handleChangeCate = (val) => { state.categoryId = val[2] || 0 } + + const listAllClass = async () => { + let res = await api.listClass() + state.allClasses = res.data + } + const listAllIndex = async () => { + let res = await api.listExamIndex() + state.formData.indexes = res.data + } + const getExam = async (id) => { + let res = await api.getExam(id) + console.log(res) + } return { ...toRefs(state), - goodRef, + formRef, submitAdd, handleBeforeUpload, handleUrlSuccess, - handleChangeCate + handleChangeCate, } } } diff --git a/admin/src/views/exam/index.vue b/admin/src/views/exam/index.vue index 945401a3..41a02bd5 100644 --- a/admin/src/views/exam/index.vue +++ b/admin/src/views/exam/index.vue @@ -2,7 +2,7 @@ - - -