|
@@ -1,155 +1,185 @@
|
|
|
<template>
|
|
|
- <div>
|
|
|
- <el-card class="box-card">
|
|
|
- <template #header>
|
|
|
- <div class="card-header">
|
|
|
- <span>添加产品</span>
|
|
|
- <el-button size="mini" style="float:right" @click="router.go(-1)">返回</el-button>
|
|
|
- <el-button size="mini" style="float:right" type="primary" @click="addProduct">添加</el-button>
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- <el-form>
|
|
|
- <el-form-item label="标题:">
|
|
|
- <el-input v-model="productDetail.title"></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="图片:">
|
|
|
- <el-upload :http-request="httpRequest" multiple :show-file-list="true" list-type="picture-card">
|
|
|
- <el-icon>
|
|
|
- <Plus />
|
|
|
- </el-icon>
|
|
|
- </el-upload>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="类型:">
|
|
|
- <el-select v-model="productDetail.type" @change="handleTypeChange" placeholder="请选择添加类型">
|
|
|
- <el-option label="服务" value="serve" />
|
|
|
- <el-option label="产品" value="product" />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="产品类型:">
|
|
|
- <el-select v-model="productDetail.ptype" :disabled="productDetail.type === 'serve'" placeholder="请选择软件或者硬件"
|
|
|
- style="width: 20vw">
|
|
|
- <el-option label="硬件" value="hardware" />
|
|
|
- <el-option label="软件" value="software" />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="是否首页展示:">
|
|
|
- <el-select v-model="productDetail.isIndex" placeholder="请选择是否首页显示" style="width: 20vw">
|
|
|
- <el-option label="是" value="true" />
|
|
|
- <el-option label="否" value="false" />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="简介:">
|
|
|
- <el-input v-model="productDetail.synopsis"></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="详情:">
|
|
|
- <EditorWithBinding v-model="productDetail.detail"></EditorWithBinding>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="产品介绍:">
|
|
|
- <EditorWithBinding v-model="productDetail.product_introduction"></EditorWithBinding>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="技术参数:">
|
|
|
- <EditorWithBinding v-model="productDetail.technical_parameters"></EditorWithBinding>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="使用说明:">
|
|
|
- <EditorWithBinding v-model="productDetail.instructions"></EditorWithBinding>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="支持软件:">
|
|
|
- <EditorWithBinding v-model="productDetail.supporting_software"></EditorWithBinding>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="可选配件:">
|
|
|
- <EditorWithBinding v-model="productDetail.optional_accessories"></EditorWithBinding>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- </el-card>
|
|
|
- </div>
|
|
|
+ <div>
|
|
|
+ <el-card class="box-card">
|
|
|
+ <template #header>
|
|
|
+ <div class="card-header">
|
|
|
+ <span>添加产品</span>
|
|
|
+ <el-button size="mini" style="float:right" @click="router.go(-1)">返回</el-button>
|
|
|
+ <el-button size="mini" style="float:right" type="primary" @click="addProduct">添加</el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <el-form>
|
|
|
+ <el-form-item label="标题:">
|
|
|
+ <el-input v-model="productDetail.title"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="图片:">
|
|
|
+ <el-upload :http-request="httpRequest" multiple :show-file-list="true" list-type="picture-card">
|
|
|
+ <el-icon>
|
|
|
+ <Plus/>
|
|
|
+ </el-icon>
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="类型:">
|
|
|
+ <el-select v-model="productDetail.type" @change="handleTypeChange" placeholder="请选择添加类型">
|
|
|
+ <el-option label="服务" value="serve"/>
|
|
|
+ <el-option label="产品" value="product"/>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="产品类型:">
|
|
|
+ <el-select v-model="productDetail.ptype" :disabled="productDetail.type === 'serve'"
|
|
|
+ placeholder="请选择软件或者硬件"
|
|
|
+ style="width: 20vw">
|
|
|
+ <el-option label="硬件" value="hardware"/>
|
|
|
+ <el-option label="软件" value="software"/>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="是否首页展示:">
|
|
|
+ <el-select v-model="productDetail.isIndex" placeholder="请选择是否首页显示" style="width: 20vw">
|
|
|
+ <el-option label="是" value="true"/>
|
|
|
+ <el-option label="否" value="false"/>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="简介:">
|
|
|
+ <el-input v-model="productDetail.synopsis"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="详情:">
|
|
|
+ <EditorWithBinding v-model="productDetail.detail"></EditorWithBinding>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="产品介绍:">
|
|
|
+ <EditorWithBinding v-model="productDetail.product_introduction"></EditorWithBinding>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="技术参数:">
|
|
|
+ <EditorWithBinding v-model="productDetail.technical_parameters"></EditorWithBinding>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="使用说明:">
|
|
|
+ <EditorWithBinding v-model="productDetail.instructions"></EditorWithBinding>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="支持软件:">
|
|
|
+ <el-upload
|
|
|
+ :http-request="httpRequests"
|
|
|
+ class="upload-demo"
|
|
|
+ drag
|
|
|
+ multiple
|
|
|
+ >
|
|
|
+ <el-icon class="el-icon--upload">
|
|
|
+ <upload-filled/>
|
|
|
+ </el-icon>
|
|
|
+ <div class="el-upload__text" style="width: 300px">
|
|
|
+ 选择上传文件
|
|
|
+ </div>
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="可选配件:">
|
|
|
+ <EditorWithBinding v-model="productDetail.optional_accessories"></EditorWithBinding>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </el-card>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { onBeforeMount, reactive, ref } from 'vue';
|
|
|
-import { useRoute, useRouter } from 'vue-router'
|
|
|
+import {onBeforeMount, reactive, ref} from 'vue';
|
|
|
+import {useRoute, useRouter} from 'vue-router'
|
|
|
import product from "../../api/product.js";
|
|
|
-import { ElMessage } from "element-plus";
|
|
|
+import {ElMessage} from "element-plus";
|
|
|
import EditorWithBinding from "../EditorWithBinding.vue";
|
|
|
-import { Plus } from "@element-plus/icons-vue";
|
|
|
+import {Plus} from "@element-plus/icons-vue";
|
|
|
import resource from "../../api/resource.js";
|
|
|
|
|
|
const route = useRoute();
|
|
|
const router = useRouter();
|
|
|
const productDetail = reactive({
|
|
|
- title: '',
|
|
|
- synopsis: '',
|
|
|
- detail: '',
|
|
|
- ptype: '',
|
|
|
- type: '',
|
|
|
- url: '',
|
|
|
- isIndex: '',
|
|
|
- product_introduction: '',
|
|
|
- technical_parameters: '',
|
|
|
- instructions: '',
|
|
|
- supporting_software: '',
|
|
|
- optional_accessories: '',
|
|
|
+ title: '',
|
|
|
+ synopsis: '',
|
|
|
+ detail: '',
|
|
|
+ ptype: '',
|
|
|
+ type: '',
|
|
|
+ url: '',
|
|
|
+ isIndex: '',
|
|
|
+ product_introduction: '',
|
|
|
+ technical_parameters: '',
|
|
|
+ instructions: '',
|
|
|
+ supporting_software: '',
|
|
|
+ optional_accessories: '',
|
|
|
})
|
|
|
const handleTypeChange = (value) => {
|
|
|
- if (value === 'serve') {
|
|
|
- productDetail.ptype = '';
|
|
|
- }
|
|
|
+ if (value === 'serve') {
|
|
|
+ productDetail.ptype = '';
|
|
|
+ }
|
|
|
}
|
|
|
const fileList = ref([])
|
|
|
|
|
|
function httpRequest(option) {
|
|
|
- //将图片存到数组中
|
|
|
- fileList.value.push(option)
|
|
|
+ //将图片存到数组中
|
|
|
+ fileList.value.push(option)
|
|
|
+}
|
|
|
+
|
|
|
+//定义一个响应式数组用来接收图片
|
|
|
+const fileLists = ref([])
|
|
|
+
|
|
|
+//自定义函数用来覆盖原有的XHR行为(默认提交行为)
|
|
|
+function httpRequests(option) {
|
|
|
+//将图片存到数组中
|
|
|
+ fileLists.value.push(option)
|
|
|
}
|
|
|
|
|
|
const addProduct = async () => {
|
|
|
- let dataForm = new FormData();
|
|
|
- dataForm.append('types', "serve")
|
|
|
- //将图片的二进制通过表单的形式发送到后台
|
|
|
- fileList.value.forEach((it, index) => {
|
|
|
- dataForm.append('file', it.file)
|
|
|
- })
|
|
|
- const fileRes = await resource.uploadResource(dataForm)
|
|
|
- productDetail.url = fileRes.data.Data
|
|
|
- const res = await product.addProduct({
|
|
|
- title: productDetail.title,
|
|
|
- synopsis: productDetail.synopsis,
|
|
|
- detail: productDetail.detail,
|
|
|
- url: productDetail.url,
|
|
|
- ptype: productDetail.ptype,
|
|
|
- type: productDetail.type,
|
|
|
- isIndex: Boolean(productDetail.isIndex),
|
|
|
- product_introduction: productDetail.product_introduction,
|
|
|
- technical_parameters: productDetail.technical_parameters,
|
|
|
- instructions: productDetail.instructions,
|
|
|
- supporting_software: productDetail.supporting_software,
|
|
|
- optional_accessories: productDetail.optional_accessories,
|
|
|
- });
|
|
|
- if (res.data.Code === 200) {
|
|
|
- ElMessage.success("添加成功")
|
|
|
- Object.assign(productDetail, {
|
|
|
- title: '',
|
|
|
- synopsis: '',
|
|
|
- detail: '',
|
|
|
- ptype: '',
|
|
|
- type: '',
|
|
|
- url: '',
|
|
|
- isIndex: '',
|
|
|
- product_introduction: '',
|
|
|
- technical_parameters: '',
|
|
|
- instructions: '',
|
|
|
- supporting_software: '',
|
|
|
- optional_accessories: '',
|
|
|
+ let dataForm = new FormData();
|
|
|
+ dataForm.append('types', "serve")
|
|
|
+ //将图片的二进制通过表单的形式发送到后台
|
|
|
+ fileList.value.forEach((it, index) => {
|
|
|
+ dataForm.append('file', it.file)
|
|
|
+ })
|
|
|
+ let dataForms = new FormData();
|
|
|
+ dataForms.append('types', "file")
|
|
|
+ //将图片的二进制通过表单的形式发送到后台
|
|
|
+ fileLists.value.forEach((it, index) => {
|
|
|
+ dataForms.append('file', it.file)
|
|
|
+ })
|
|
|
+ const fileRes = await product.uploadFile(dataForms)
|
|
|
+ productDetail.supporting_software = fileRes.data.Data
|
|
|
+ const resoursRes = await resource.uploadResource(dataForm)
|
|
|
+ productDetail.url = resoursRes.data.Data
|
|
|
+ const res = await product.addProduct({
|
|
|
+ title: productDetail.title,
|
|
|
+ synopsis: productDetail.synopsis,
|
|
|
+ detail: productDetail.detail,
|
|
|
+ url: productDetail.url,
|
|
|
+ ptype: productDetail.ptype,
|
|
|
+ type: productDetail.type,
|
|
|
+ isIndex: Boolean(productDetail.isIndex),
|
|
|
+ product_introduction: productDetail.product_introduction,
|
|
|
+ technical_parameters: productDetail.technical_parameters,
|
|
|
+ instructions: productDetail.instructions,
|
|
|
+ supporting_software: productDetail.supporting_software,
|
|
|
+ optional_accessories: productDetail.optional_accessories,
|
|
|
});
|
|
|
- } else {
|
|
|
- ElMessage.error(res.data.Msg)
|
|
|
- }
|
|
|
+ if (res.data.Code === 200) {
|
|
|
+ ElMessage.success("添加成功")
|
|
|
+ Object.assign(productDetail, {
|
|
|
+ title: '',
|
|
|
+ synopsis: '',
|
|
|
+ detail: '',
|
|
|
+ ptype: '',
|
|
|
+ type: '',
|
|
|
+ url: '',
|
|
|
+ isIndex: '',
|
|
|
+ product_introduction: '',
|
|
|
+ technical_parameters: '',
|
|
|
+ instructions: '',
|
|
|
+ supporting_software: '',
|
|
|
+ optional_accessories: '',
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ ElMessage.error(res.data.Msg)
|
|
|
+ }
|
|
|
}
|
|
|
onBeforeMount(async () => {
|
|
|
- if (route.query.id) {
|
|
|
- const res = await product.getProductDetail({ id: route.query.id })
|
|
|
- console.log(res.data)
|
|
|
- Object.assign(productDetail, res.data.Data);
|
|
|
- }
|
|
|
+ if (route.query.id) {
|
|
|
+ const res = await product.getProductDetail({id: route.query.id})
|
|
|
+ console.log(res.data)
|
|
|
+ Object.assign(productDetail, res.data.Data);
|
|
|
+ }
|
|
|
})
|
|
|
</script>
|
|
|
|