# Conflicts:
#	src/router/routes.ts
#	src/views/Commodity/AddProduct.vue
This commit is contained in:
sa_10_0 2024-11-03 13:35:13 +08:00
commit 658b79a19e
9 changed files with 494 additions and 489 deletions

View File

@ -21,15 +21,16 @@
<span>用户管理</span> <span>用户管理</span>
</template> </template>
<el-menu-item index="/PersonalCenter">
<el-icon><UserFilled /></el-icon>
<span slot="title">个人中心</span>
</el-menu-item>
<el-menu-item index="/UserManagement"> <el-menu-item index="/UserManagement">
<el-icon><List /></el-icon> <el-icon><List /></el-icon>
<span slot="title">用户列表</span> <span slot="title">用户列表</span>
</el-menu-item> </el-menu-item>
<el-menu-item index="/PersonalCenter">
<el-icon><UserFilled /></el-icon>
<span slot="title">个人中心</span>
</el-menu-item>
</el-sub-menu> </el-sub-menu>
<el-sub-menu index="2"> <el-sub-menu index="2">
@ -64,6 +65,17 @@
</el-menu-item> </el-menu-item>
</el-sub-menu> </el-sub-menu>
<el-sub-menu index="3">
<template #title>
<el-icon><HomeFilled /></el-icon>
<span>订单管理</span>
</template>
<el-menu-item index="/OrderList">
<el-icon><Menu /></el-icon>
<span slot="title">订单列表</span>
</el-menu-item>
</el-sub-menu>
</el-menu> </el-menu>
</el-aside> </el-aside>
</el-aside> </el-aside>

View File

@ -13,16 +13,16 @@ export const routes = [
path: '/manage', path: '/manage',
component: () => import("@/layout/Manage.vue"), component: () => import("@/layout/Manage.vue"),
children:[ children:[
{
path: '/UserManagement',
name:'用户列表',
component: ()=> import("../views/User/UserManagement.vue")
},
{ {
path: '/PersonalCenter', path: '/PersonalCenter',
name:'个人中心', name:'个人中心',
component: ()=> import("../views/User/PersonalCenter.vue") component: ()=> import("../views/User/PersonalCenter.vue")
}, },
{
path: '/UserManagement',
name:'用户列表',
component: ()=> import("../views/User/UserManagement.vue")
},
{ {
path: '/AddProduct', path: '/AddProduct',
name: '添加商品', name: '添加商品',
@ -39,10 +39,15 @@ export const routes = [
component: ()=> import("../views/Commodity/TypeManagement.vue") component: ()=> import("../views/Commodity/TypeManagement.vue")
}, },
{ {
path:'/AddCoupons', path: '/OrderList',
name:'添加优惠券', name: '订单列表',
component:()=>import("../views/Coupons/AddCoupons.vue") component: ()=> import("../views/Orders/OrderList.vue")
} }
] ]
},
{
path: '/Test',
name:'测试页面',
component: () => import("../views/test.vue")
} }
] ]

View File

@ -1,5 +1,4 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import myAxios from '../api/myAxios'
export const userStore = defineStore( 'user' , { export const userStore = defineStore( 'user' , {
//state是应用的核心数据通常用于管理用户信息、应用设置、数据列表等。 //state是应用的核心数据通常用于管理用户信息、应用设置、数据列表等。
@ -26,7 +25,6 @@ export const userStore = defineStore( 'user' , {
//更新state //更新state
updateUser(payLoad : any) { updateUser(payLoad : any) {
this.loginUser = payLoad this.loginUser = payLoad
console.log(payLoad,2654615165)
} }
} }
}) })

View File

@ -1,190 +1,172 @@
<template> <template>
<!-- 添加商品图片-->
<div style="height: auto;margin-bottom: 10px;width: 480px;">
<div style="font-size: 20px;margin-bottom: 10px">添加商品图片</div>
<el-upload action="#" v-model:file-list="uploadedFiles" list-type="picture-card" :auto-upload="false" multiple="true">
<el-icon><Plus /></el-icon>
<template #file="{ file }">
<div> <div>
<img class="el-upload-list__item-thumbnail" :src="file.url" alt="" /> <!-- 表单 ref prop绑定 用于重置表单 -->
<span class="el-upload-list__item-actions"> <el-form ref="resetFormData" :model="form" label-width="auto" style="width: 750px" size="large">
<span <el-form-item label="添加商品图片">
class="el-upload-list__item-preview" <!-- 下面的event的作用,传入当前事件对象 -->
@click="handlePictureCardPreview(file)" <el-upload
> action="#"
<el-icon><zoom-in /></el-icon> list-type="picture-card"
</span> :auto-upload="false"
<span multiple="true"
v-if="!disabled" :on-remove="handleRemove"
class="el-upload-list__item-delete" @change="(event: any) => handleChange(event, 0)"
@click="handleRemove(file)" limit="1" >
> <el-icon>
<el-icon><Delete /></el-icon> <Plus />
</span> </el-icon>
</span>
</div>
</template>
</el-upload> </el-upload>
<!-- 添加图文描述--> </el-form-item>
<div style="margin-bottom: 10px;"> <!-- 添加图文描述-->
<div style="font-size: 20px;margin-bottom: 10px">添加图文描述</div> <el-form-item label="添加图文描述">
<el-upload action="#" v-model:file-list="uploadedDescription" list-type="picture-card" :auto-upload="false" multiple="true"> <el-upload
<el-icon><Plus /></el-icon> action="#"
list-type="picture-card"
<template #file="{ file }"> :auto-upload="false"
<div> multiple="true"
<img class="el-upload-list__item-thumbnail" :src="file.url" alt="" /> :on-change="(event: any) => handleChange(event, 1)"
<span class="el-upload-list__item-actions"> limit="1"
<span :on-remove="handleRemove"
class="el-upload-list__item-preview"
@click="handlePictureCardPreview(file)"
> >
<el-icon><zoom-in /></el-icon> <el-icon>
</span> <Plus />
<span </el-icon>
v-if="!disabled"
class="el-upload-list__item-delete"
@click="descriptionRemove(file)"
>
<el-icon><Delete /></el-icon>
</span>
</span>
</div>
</template>
</el-upload> </el-upload>
</el-form-item>
<el-dialog v-model="dialogVisible"> <el-form-item label="产品名称" prop="name">
<img w-full :src="dialogImageUrl" alt="Preview Image" />
</el-dialog>
</div>
<el-dialog v-model="dialogVisible">
<img w-full :src="dialogImageUrl" alt="Preview Image" />
</el-dialog>
</div>
<!-- 表单-->
<div style="position: absolute;right: 20px;top: 100px;max-width: 50%" >
<el-form :model="form" label-width="auto" style="width: 750px" size="large">
<el-form-item label="产品名称">
<el-input v-model="form.name" /> <el-input v-model="form.name" />
</el-form-item> </el-form-item>
<el-form-item label="产品价格"> <el-form-item label="产品价格" prop="price">
<el-input v-model="form.price" /> <el-input v-model="form.price" />
</el-form-item> </el-form-item>
<el-form-item label="产品"> <el-form-item label="产品简介" prop="intro">
<el-input v-model="form.quantity" /> <el-input v-model="form.intro" />
</el-form-item> </el-form-item>
<el-form-item label="是否为限定类产品" > <el-form-item label="当前库存" prop="inventory">
<el-select v-model="form.region" placeholder="否"> <el-input v-model="form.inventory" />
<el-option label="是" value="ture" /> </el-form-item>
<el-option label="否" value="false" /> <el-form-item label="是否为限定类产品" prop="festivalOrder">
<el-select v-model="form.festivalOrder" placeholder="请选择" @change="(event: any) => loadForm(event, 0)">
<el-option label="是" value="1" />
<el-option label="否" value="0" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item v-if="form.region=='ture' " label="节日名称"> <!-- <el-form-item v-if="form.region=='ture' " label="节日名称">
<el-input v-model="form.festivalName" /> <el-input v-model="form.festivalName" />
</el-form-item> -->
<el-form-item label="产品类别" prop="type">
<el-select v-model="typeList.value" placeholder="请选择" @change="(event: any) => loadForm(event, 1)">
<el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value1" />
</el-select>
</el-form-item> </el-form-item>
<el-form-item label="产品类型" > <el-form-item label="商品标签" prop="label">
<el-radio-group v-model="form.resource" > <el-input v-model="form.label" type="textarea" placeholder="" />
<el-radio value="1">材料包</el-radio>
<el-radio value="2">手持物</el-radio>
<el-radio value="3">头饰</el-radio>
<el-radio value="4">定制</el-radio>
</el-radio-group>
</el-form-item> </el-form-item>
<el-form-item label="商品标签"> <el-form-item label="商品详细描述" prop="introDetail">
<el-input v-model="form.label" type="textarea" placeholder=""/> <el-input v-model="form.introDetail" type="textarea" placeholder="产品尺寸,服务等" />
</el-form-item>
<el-form-item label="详情描述">
<el-input v-model="form.desc" type="textarea" placeholder="产品尺寸,服务等"/>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="addProduct">上架</el-button> <el-button type="primary" @click="onSubmit">上架</el-button>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="resetForm">重置</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref,reactive,onMounted } from 'vue'; import { ref, onMounted } from 'vue';
import { Delete, Plus, ZoomIn } from '@element-plus/icons-vue'; import { Plus } from '@element-plus/icons-vue';
import {ElMessage, type UploadFile} from 'element-plus'; import { ElMessage, type UploadFile , type UploadProps } from 'element-plus';
import myAxios from "@/api/myAxios"; import myAxios from "@/api/myAxios";
const fileSimple = ref() //
const dialogImageUrl = ref('');
const dialogVisible = ref(false);
const disabled = ref(false);
const uploadedFiles = ref<UploadFile[]>([]);// const uploadedFiles = ref<UploadFile[]>([]);//
const uploadedDescription = ref<UploadFile[]>([]);// const uploadedDescription = ref<UploadFile[]>([]);//
const handleRemove = (file: UploadFile) => { const resetFormData = ref()
uploadedFiles.value = uploadedFiles.value.filter((f) => f.uid !== file.uid); const form = ref({
}; name: '',
const descriptionRemove = (file: UploadFile) => { price: '', //
uploadedDescription.value = uploadedDescription.value.filter((f) => f.uid !== file.uid); intro: '',//
} festivalOrder: '',//
const handlePictureCardPreview = (file: UploadFile) => { type: '',//
dialogImageUrl.value = file.url!; label: '',//
dialogVisible.value = true; introDetail: '',//
}; goodImg: '', //url
const form = reactive({ detailImg: '', //url
name:'', inventory: '' //
price:'',
quantity:'',//
region:'',//
festivalName:'',//
resource:'',//
label:'',//
desc:'',//
}) })
onMounted(()=>{ const typeList: any = ref([
upload() {
addProduct() value1: '',
}) label: ''
const addProduct = async () => { }
const res = await myAxios.post('goods/add',{ ])
name : form.name, onMounted(() => {
price : form.price, getTypeList() //select
inventory : form.quantity, })
type: form.resource, const getTypeList = async () => { //
label : form.label, const res = await myAxios.post('/category/list', {}) //
intro : form.desc, for (let key in res.data.data) { //
festivalOrder : form.festivalName typeList.value[key] = {
}) value1: res.data.data[key].typeName,
label: res.data.data[key].typeName
// if(res.data.code == 1){ }
// ElMessage({
// message: '',
// type: 'success'
// })
// }else{
// ElMessage({
// message: '',
// type: 'error'
// })
// }
} }
const upload = async () => {
const res = await myAxios.post('file/upload/server',{
multipartFile : uploadedFiles.value,
biz : uploadedDescription.value
})
} }
// onMounted(() => { const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
// getProductInformation() console.log(uploadFile, uploadFiles)
// }) }
// const getProductInformation = async () => { //
// const res: any = await myAxios.get('') const onSubmit = async () => {
// console.log(res) const values = Object.values(form.value);
// if (res.code === 1 && res.data) { // 使some()
// if (values.some(value => value === null || value === undefined || value === '')) {
// ElMessage({
// } else { type:'warning',
// message.error(`${res.message}`); message:'请检查表单数据是否完整填写'
// backPage() })
// } return; //
// } }
const onSubmit = () => { const res = await myAxios.post('/goods/add', { ...form.value })
console.log('submit!') if (res.data.code === 1) {
ElMessage({
type: 'success',
message: "提交成功"
})
} else {
ElMessage.error("服务错误")
}
}
//
const handleChange = async (file: any, flag: number) => {
fileSimple.value = file
let formData = new FormData() // FormData
formData.append("file", fileSimple.value.raw) //fileSimple.value.raw formData
const res = await myAxios({ //
url: '/file/upload/server/not_login',
method: 'post',
headers: {
'content-Type': 'multipart/form-data'
},
data: {
biz: "test",
// formDatafile
file: formData.get("file")
}
})
if (res.data.code === 1) {
// flag0 flag1
flag ? form.value.detailImg = res.data.data : form.value.goodImg = res.data.data
}
}
//
const loadForm = (value: any, flag: number) => {
flag ? form.value.type = value : form.value.festivalOrder = value // flag=1 "" flag=0
}
//
const resetForm = () =>{
resetFormData.value.resetFields()
} }
</script> </script>

View File

@ -1,7 +1,9 @@
<template> <template>
<!-- 修改前请注释以前的 -->
<!-- 搜索 -->
<div> <div>
<div> <el-input style="width: 200px; height: 30px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入商品名称"
<el-input style="width: 200px; height: 30px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入商品名称" v-model="username"></el-input> v-model="username"></el-input>
<el-form-item label="商品类型" style="width: 200px; margin-right: 10px;display: inline-block"> <el-form-item label="商品类型" style="width: 200px; margin-right: 10px;display: inline-block">
<el-select v-model="types" placeholder="请选择"> <el-select v-model="types" placeholder="请选择">
<el-option label="材料包" value="材料包" /> <el-option label="材料包" value="材料包" />
@ -21,185 +23,94 @@
<el-button type="warning" @click="reset" style="height:25px">重置</el-button> <el-button type="warning" @click="reset" style="height:25px">重置</el-button>
</div> </div>
<div style="margin: 15px 0"> <div style="margin: 15px 0">
<el-popconfirm <el-popconfirm class="ml-5" confirm-button-text='确定' cancel-button-text='取消' icon="InfoFilled" icon-color="red"
class="ml-5" title="您确定批量删除这些数据吗?" @confirm="delBatch" width=180>
confirm-button-text='确定'
cancel-button-text='取消'
icon="InfoFilled"
icon-color="red"
title="您确定批量删除这些数据吗?"
@confirm="delBatch"
width=180
>
<template #reference> <template #reference>
<el-button style="height: 25px" class="ml-5" type="danger">批量删除 <el-icon style="margin-left: 5px;"><Remove /></el-icon></el-button> <el-button style="height: 25px" class="ml-5" type="danger">批量删除 <el-icon style="margin-left: 5px;">
<Remove />
</el-icon></el-button>
</template> </template>
</el-popconfirm> </el-popconfirm>
</div> </div>
<el-table :data="tableData" border stripe header-cell-class-name="headerBg" :cell-style="{textAlign: 'center'}" <!-- 数据展示 -->
@selection-change="handleSelectionChange" :header-cell-style="{'text-align': 'center'}" <el-table :data="tableData" border stripe header-cell-class-name="headerBg"
> :cell-style="{ 'text-align': 'center', 'font-size': '16px' }" @selection-change="handleSelectionChange"
:header-cell-style="{ 'text-align': 'center' }">
<el-table-column type="selection" width="55"></el-table-column> <el-table-column type="selection" width="55"></el-table-column>
<el-table-column label="商品编号" width="80"> <el-table-column prop="id" label="商品编号" width="80"></el-table-column>
<template #default="scope"> <el-table-column prop="goodImg" label="商品图片">
<div>
<span style="align-items: center">{{ scope.row.id }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="商品图片">
<template #default="scope"> <template #default="scope">
<div> <div>
<img :src="scope.row.goodImg" alt="" style="height: 50px;"> <img :src="scope.row.goodImg" alt="" style="height: 50px;">
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="商品名称"> <el-table-column prop="name" label="商品名称"></el-table-column>
<template #default="scope"> <el-table-column prop="price" label="商品价格" width="180"></el-table-column>
<div> <el-table-column prop="type" label="商品类型"></el-table-column>
<span style="margin-left: 10px">{{ scope.row.name }}</span> <el-table-column prop="inventory" label="商品数量"></el-table-column>
</div> <el-table-column prop="createTime" label="创建时间"></el-table-column>
</template> <el-table-column prop="updateTime" label="更新时间"></el-table-column>
</el-table-column>
<el-table-column label="商品价格" width="180">
<template #default="scope">
<div>
<span style="margin-left: 10px">{{ scope.row.price }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="商品类型">
<template #default="scope">
<div>
<span style="margin-left: 10px">{{ scope.row.type }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="商品数量">
<template #default="scope">
<div>
<span style="margin-left: 10px">{{ scope.row.inventory }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="商品状态"> <el-table-column label="商品状态">
<template #default="scope"> <template #default="scope">
<div> <div>
<span style="margin-left: 10px" v-if="scope.row.isShelves==1">上架</span> <span style="margin-left: 10px" v-if="scope.row.isShelves == 1">上架</span>
<span style="margin-left: 10px" v-if="scope.row.isShelves==0">下架</span> <span style="margin-left: 10px" v-if="scope.row.isShelves == 0">下架</span>
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" width="250px"> <el-table-column label="操作" width="250px">
<template #default="scope"> <template #default="scope">
<el-button size="small" @click="handleView(scope.$index, scope.row)"> <el-button size="small" @click="ReviseOrView(scope.$index, scope.row , 0)">
详情 详情
</el-button> </el-button>
<el-button size="small" @click="handleRevise(scope.$index, scope.row)"> <el-button size="small" @click="ReviseOrView(scope.$index, scope.row, 1)">
编辑 编辑
</el-button> </el-button>
<el-button size="small" @click="handleOff(scope.$index, scope.row)"> <el-button size="small" @click="handleOff(scope.$index, scope.row)">
<div v-if="scope.row.isShelves==1">下架 </div> <div v-if="scope.row.isShelves == 1">下架 </div>
<div v-if="scope.row.isShelves==0">上架 </div> <div v-if="scope.row.isShelves == 0">上架 </div>
</el-button> </el-button>
<el-button <el-popconfirm class="ml-5" confirm-button-text='确定' cancel-button-text='取消' icon="InfoFilled" icon-color="red"
size="small" title="是否确认删除" @confirm="deleteProduct(scope.row.id)" width=180>
type="danger" <template #reference>
@click="handleDelete(scope.$index, scope.row)" <el-button class="ml-5" type="danger">删除</el-button>
> </template>
删除 </el-popconfirm>
</el-button> <el-popconfirm confirm-button-text='确定' cancel-button-text='取消' icon="el-icon-info" icon-color="red"
<el-popconfirm title="您确定删除吗?">
confirm-button-text='确定'
cancel-button-text='取消'
icon="el-icon-info"
icon-color="red"
title="您确定删除吗?"
>
</el-popconfirm> </el-popconfirm>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<!-- 分页器 -->
<div style="padding: 10px 0"> <div style="padding: 10px 0">
<el-pagination <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
@size-change="handleSizeChange" :current-page="searchParams.current" :page-size="searchParams.pageSize" :page-sizes="[5, 10, 15, 20]"
@current-change="handleCurrentChange" :small="null" :disabled="null" :background="null" layout="total, sizes, prev, pager, next, jumper"
:current-page="pageNum" :total="total" />
:page-size="pageSize"
:page-sizes="[2, 5, 10, 20]"
:small="null"
:disabled="null"
:background="null"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
/>
</div> </div>
</div> <!-- 编辑/详情表单 -->
<el-dialog v-model="detailDialogVisible" title="商品详情"> <el-dialog v-model="DialogVisible" :title="title">
<el-form label-width="100px"> <el-form label-width="100px" :disabled="disabled">
<el-form-item label="商品编号"> <el-form-item label="商品编号">
<el-input v-model="selectedProduct.id" disabled></el-input> <el-input v-model="editForm.id" disabled></el-input>
</el-form-item> </el-form-item>
<el-form-item label="商品图片"> <el-form-item label="商品图片">
<div v-if="selectedProduct.goodImg"> <div v-if="editForm.goodImg">
<img :src="selectedProduct.goodImg" alt="类别图标" class="thumbnail" style="width: 100px; height: 100px;"/> <img :src="editForm.goodImg" alt="商品图标" class="thumbnail" style="width: 100px; height: 100px;" />
</div> </div>
</el-form-item> <el-upload
<el-form-item label="商品名称"> action="#"
<el-input v-model="selectedProduct.name" disabled></el-input> list-type="picture-card"
</el-form-item> :auto-upload="false"
<el-form-item label="商品价格"> multiple="true"
<el-input v-model="selectedProduct.price" disabled></el-input> :on-remove="handleRemove"
</el-form-item> @change="(event: any) => handleChange(event, 0)"
<el-form-item label="商品类型"> limit="1" >
<el-select v-model="selectedProduct.type" placeholder="请选择" disabled> <el-icon>
<el-option label="材料包" value="材料包" /> <Plus/>
<el-option label="手持物" value="手持物" /> </el-icon>
<el-option label="头饰" value="头饰" />
<el-option label="定制" value="定制" />
<el-option label="积分兑换" value="积分兑换" />
</el-select>
</el-form-item>
<el-form-item label="商品数量">
<el-input v-model="selectedProduct.inventory" disabled></el-input>
</el-form-item>
<el-form-item label="商品状态">
<el-select v-model="selectedProduct.isShelves" placeholder="请选择" disabled>
<el-option label="上架" value="上架" />
<el-option label="下架" value="下架" />
</el-select>
</el-form-item>
<el-form-item label="是否为限定产品">
<el-select v-model="selectedProduct.region" placeholder="请选择" disabled>
<el-option label="是" value="是" />
<el-option label="否" value="否" />
</el-select>
</el-form-item>
<el-form-item label="商品标签">
<el-input v-model="selectedProduct.label" disabled></el-input>
</el-form-item>
<el-form-item label="商品描述">
<el-input type="textarea" v-model="selectedProduct.introDetailintroDetail" disabled></el-input>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="detailDialogVisible = false">取消</el-button>
</span>
</template>
</el-dialog>
<el-dialog v-model="editDialogVisible" title="商品编辑">
<el-form label-width="100px">
<el-form-item label="商品编号">
<el-input v-model="editForm.id"></el-input>
</el-form-item>
<el-form-item label="商品图片">
<el-upload action="#" list-type="picture" :auto-upload="false">
<el-icon><Plus /></el-icon>
<template #file="{ file }">
<img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
</template>
</el-upload> </el-upload>
</el-form-item> </el-form-item>
<el-form-item label="商品名称"> <el-form-item label="商品名称">
@ -208,123 +119,92 @@
<el-form-item label="商品价格"> <el-form-item label="商品价格">
<el-input v-model="editForm.price"></el-input> <el-input v-model="editForm.price"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="商品类型"> <el-form-item label="产品类别" prop="type">
<el-select v-model="editForm.type" placeholder="请选择"> <el-select v-model="editForm.type" @change="(event: any) => loadForm(event, 1)">
<el-option label="材料包" value="材料包" /> <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value1" />
<el-option label="手持物" value="手持物" />
<el-option label="头饰" value="头饰" />
<el-option label="定制" value="定制" />
<el-option label="积分兑换" value="定制" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="商品数量"> <el-form-item label="商品数量">
<el-input v-model="editForm.inventory"></el-input> <el-input v-model="editForm.inventory"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="商品状态"> <el-form-item label="商品状态">
<el-select v-model="editForm.isShelves" disabled> <el-select v-model="editForm.isShelves">
<el-option label="上架" value="上架" /> <el-option label="上架" value="上架" />
<el-option label="下架" value="下架" /> <el-option label="下架" value="下架" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="是否为限定产品"> <el-form-item label="是否为限定产品" prop="festivalOrder">
<el-select v-model="editForm.region" placeholder="请选择"> <el-select v-model="editForm.festivalOrder" @change="(event: any) => loadForm(event, 0)">
<el-option label="是" value="" /> <el-option label="是" value="1" />
<el-option label="否" value="" /> <el-option label="否" value="0" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="商品标签"> <el-form-item label="商品标签">
<el-input v-model="editForm.label"></el-input> <el-input v-model="editForm.label"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="商品图文">
<div v-if="editForm.detailImg">
<img :src="editForm.detailImg" alt="商品图标" class="thumbnail" style="width: 100px; height: 100px;" />
</div>
<el-upload
action="#"
list-type="picture-card"
:auto-upload="false"
multiple="true"
:on-remove="handleRemove"
@change="(event: any) => handleChange(event, 0)"
limit="1" >
<el-icon>
<Plus/>
</el-icon>
</el-upload>
</el-form-item>
<el-form-item label="商品描述"> <el-form-item label="商品描述">
<el-input type="textarea" v-model="editForm.introDetail"></el-input> <el-input type="textarea" v-model="editForm.introDetail"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> <template #footer >
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="editDialogVisible = false">取消</el-button> <el-button @click="DialogVisible = false" :disabled="disabled">取消</el-button>
<el-button type="primary" @click="saveEdit">保存</el-button> <el-button type="primary" @click="saveEdit" :disabled="disabled">确认</el-button>
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ElMessage } from 'element-plus'; import { ElMessage , type UploadProps } from 'element-plus';
import { ref, onMounted } from 'vue'; import { ref, onMounted, toRaw } from 'vue';
import myAxios from "@/api/myAxios"; import myAxios from "@/api/myAxios";
// const total = ref(0); //
const total = ref(0);
const id = ref([]); const id = ref([]);
// const searchParams: any = ref({ //
const searchParams: any = ref({ current: 1, //
// pageSize: 5 //
current: 1,
//
pageSize: 5
}) })
const fileSimple = ref()
const disabled = ref(true)
const title = ref('')
const username = ref(''); const username = ref('');
const detailDialogVisible = ref(false); const DialogVisible = ref(false);
const editDialogVisible = ref(false);
const types = ref(''); const types = ref('');
const Region = ref(''); const Region = ref('');
let selectedProduct = ref(''); const tableData : any= ref([]);
const loading = ref(false) const editForm : any = ref({});
const tableData = ref([]); const typeList: any = ref([
let editForm = ref({ {
id: '', value1: '',
goodImg: '', label: ''
name: '', }
price: '', ])
type: '', onMounted(() => { //
inventory: '', getProductList()
isShelves: '', getTypeList()
attribute:'',
region: '',
label: '',
introDetail: '',
});
//
onMounted(() => {
getGoodList()
}) })
const handleSelectionChange = (row: any) => { const getProductList = async () => {
id.value = JSON.parse(JSON.stringify(row));
};
const handleView = (index: number, row: any) => {
selectedProduct = row;
detailDialogVisible.value = true;
};
const handleRevise = (index: number, row: any) => {
selectedProduct = row;
editDialogVisible.value = true;
editForm.value = row;
};
const handleOff = (index: number, row: any) => {
console.log()
if (row.isShelves === 0) {
row.isShelves = 1;//01
console.log(row.isShelves)
} else if (row.isShelves ===1) {
row.isShelves = 0;
}
}
const handleDelete = (index: number, row: any) => {
const confirmDelete = window.confirm('您确定要删除该商品吗?');
if (confirmDelete) {
tableData.value = tableData.value.filter((item, i) => i!== index);
ElMessage({
message: '删除成功',
type: 'success',
});
}
};
const getGoodList = async () => {
loading.value = true;
try { try {
const res = await myAxios.post('/goods/list/page', {...searchParams.value }); const res = await myAxios.post('/goods/list/page', { ...searchParams.value });
console.log(res.data) // console.log(res.data)
if (res.data.code === 1) { if (res.data.code === 1) {
tableData.value = res.data.data.records; tableData.value = res.data.data.records;
total.value = parseInt(res.data.data.total)// total.value = parseInt(res.data.data.total)//
@ -339,67 +219,116 @@ const getGoodList = async () => {
}); });
} }
} }
// const getTypeList = async () => {
const handleSizeChange =(newSize : any)=>{ const res = await myAxios.post('/category/list', {}) //
searchParams.value.pageSize = newSize // for (let key in res.data.data) { //
getGoodList() typeList.value[key] = {
value1: res.data.data[key].typeName,
label: res.data.data[key].typeName
}
}
} }
// const saveEdit = async () => { //
const handleCurrentChange = (Current : any) => { const res = await myAxios.post('/goods/update',{...editForm.value})
if( res.data.code === 1 ) {
ElMessage({
type: 'success',
message: '更新成功'
})
DialogVisible.value = false
} else {
ElMessage.error('更新失败,请检查字段')
}
}
//
const deleteProduct = async (index: number) => {
console.log(typeof index)
const res = await myAxios.post('/goods/delete', { id: index })
console.log(res)
if (res.data.code === 1) {
ElMessage({
type: 'success',
message: '删除成功',
})
getProductList()
}
getTypeList()
}
const handleSelectionChange = (row: any) => {
id.value = JSON.parse(JSON.stringify(row));
};
//
const ReviseOrView = (index: number, row: any , flag : number) => {
//flag disabled
flag ? (title.value = "编辑商品" , disabled.value = false) : (title.value = "商品详情" , disabled.value = true)
DialogVisible.value = true;
editForm.value = row;
};
//()
const handleOff = async (index: number, row: any) => {
row.isShelves ? row.isShelves = 0 : row.isShelves = 1 //
editForm.value = row;
const res = await myAxios.post('/goods/update',{...editForm.value})
if(res.data.code === 1) {
ElMessage({
type:'success',
message:'更新成功'
})
}
}
//
const handleSizeChange = (newSize: any) => {
searchParams.value.pageSize = newSize //
getProductList()
}
//
const handleCurrentChange = (Current: any) => {
searchParams.value.current = Current searchParams.value.current = Current
getGoodList() getProductList()
} }
const reset = () => { const reset = () => {
username.value = ''; username.value = '';
types.value = ''; types.value = '';
Region.value = ''; Region.value = '';
}; };
// const saveEdit = () => { // --
// const indexToUpdate = tableData.findIndex(item => item.id === editForm.value.id); const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
// if (indexToUpdate!== -1) { console.log(uploadFile, uploadFiles)
// tableData[indexToUpdate] = { }
// ...tableData[indexToUpdate], //
// ...editForm.value, const loadForm = (value: any, flag: number) => {
// }; flag ? editForm.value.type = value : editForm.value.festivalOrder = value // flag=1 "" flag=0
// ElMessage({ }
// message: '', //
// type: 'success', const handleChange = async (file: any, flag: number) => {
// }); fileSimple.value = file
// editDialogVisible.value = false; let formData = new FormData() // FormData
// }; formData.append("file", fileSimple.value.raw) //fileSimple.value.raw formData
// }; const res = await myAxios({ //
url: '/file/upload/server/not_login',
method: 'post',
headers: {
'content-Type': 'multipart/form-data'
},
data: {
biz: "test",
file: formData.get("file") // formDatafile
}
})
if (res.data.code === 1) {
// flag0 flag1
flag ? editForm.value.detailImg = res.data.data : editForm.value.goodImg = res.data.data
}
}
// const getListPage = async () => { const delBatch =()=>{
// await instance.post('/goods/list/page').then(res => { //
// console.log(res.data.data); }
// res.data.data.forEach(item => { const load =()=>{}
// console.log(item);
// });
// tableData.value = res.data.data;
// });
// };
const delBatchSuccess = () => {
ElMessage({
message: '批量删除成功',
type: 'success',
});
};
// const delBatch = async () => {
// await instance.post('').then(res => {
// if (res.data.code === '200') {
// load();
// } else {
// ElMessage({
// message: '',
// type: 'error',
// });
// }
// });
// };
</script> </script>
<style scoped> <style scoped>
.headerBg { .headerBg {
background-color: #eee!important; background-color: #eee !important;
} }
</style> </style>

View File

@ -6,11 +6,20 @@
<el-dialog v-model="dialogVisible" title="商品类别" width="500"> <el-dialog v-model="dialogVisible" title="商品类别" width="500">
<el-form :model="typeForm" label-width="auto" style="max-width: 600px"> <el-form :model="typeForm" label-width="auto" style="max-width: 600px">
<el-form-item label="类别图标"> <el-form-item label="添加类别图片">
<div v-if="typeForm.typeUrl"> <!-- 下面的event的作用,传入当前事件对象 -->
<img :src="typeForm.typeUrl" alt="类别图标" class="thumbnail" style="width: 100px; height: 100px;" /> <el-upload
</div> action="#"
<input type="file" @change="handleFileUpload" accept="image/*" /> list-type="picture-card"
:auto-upload="false"
multiple="true"
:on-remove="handleRemove"
@change="(event: any) => handleChange(event)"
limit="1" >
<el-icon>
<Plus />
</el-icon>
</el-upload>
</el-form-item> </el-form-item>
<el-form-item label="类别名"> <el-form-item label="类别名">
<el-input v-model="typeForm.typeName" /> <el-input v-model="typeForm.typeName" />
@ -19,7 +28,6 @@
<el-input v-model="typeForm.typeIntro" /> <el-input v-model="typeForm.typeIntro" />
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer #default="{ row, $index }"> <template #footer #default="{ row, $index }">
<div class="dialog-footer"> <div class="dialog-footer">
<el-button @click="cancel">取消</el-button> <el-button @click="cancel">取消</el-button>
@ -33,6 +41,7 @@
<el-table :data="tableData" border style="width: 100%;" :header-cell-style="{ 'text-align': 'center' }" <el-table :data="tableData" border style="width: 100%;" :header-cell-style="{ 'text-align': 'center' }"
@selection-change="handleSelectionChange" :cell-style="{ 'text-align': 'center', 'font-size': '16px' }"> @selection-change="handleSelectionChange" :cell-style="{ 'text-align': 'center', 'font-size': '16px' }">
<el-table-column type="selection" width="55"></el-table-column> <el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="id" label="类别编号" width="150"></el-table-column>
<el-table-column prop="typeUrl" label="类别图片" width="300"> <el-table-column prop="typeUrl" label="类别图片" width="300">
<!-- 插槽拿到父组件的值typeUrl --> <!-- 插槽拿到父组件的值typeUrl -->
<!-- scope 提供了关于当前行的信息 --> <!-- scope 提供了关于当前行的信息 -->
@ -56,10 +65,10 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ElMessage } from 'element-plus'; import { ElMessage ,type UploadProps} from 'element-plus';
import { onMounted, ref } from 'vue' import { onMounted, ref } from 'vue'
import myAxios from '@/api/myAxios'; import myAxios from '@/api/myAxios';
const fileSimple = ref() //
const selectedItems = ref([]) const selectedItems = ref([])
const dialogVisible = ref(false) const dialogVisible = ref(false)
// //
@ -84,9 +93,34 @@ const getTypeList = async () => {
// console.log(res.data.data) // console.log(res.data.data)
if (res.data.code === 1) { if (res.data.code === 1) {
tableData.value = res.data.data tableData.value = res.data.data
} else {
ElMessage.error('获取类别列表失败,请检查服务')
} }
} }
//flag
const handleChange = async (file: any) => {
fileSimple.value = file
let formData = new FormData() // FormData
formData.append("file", fileSimple.value.raw) //fileSimple.value.raw formData
const res = await myAxios({ //
url: '/file/upload/server/not_login',
method: 'post',
headers: {
'content-Type': 'multipart/form-data'
},
data: {
biz: "test",
file: formData.get("file") // formDatafile
}
})
if ( res.data.code === 1) {
typeForm.value.typeUrl = res.data.data
}
}
// --
const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
console.log(uploadFile, uploadFiles)
}
// //
const showForm = async () => { const showForm = async () => {
dialogVisible.value = true; dialogVisible.value = true;
@ -99,7 +133,7 @@ const cancel = () => {
} }
// //
const addOrUpdateType = async () => { const addOrUpdateType = async () => {
// //(*)
if (typeForm.value.typeName?.indexOf(' ') !== -1 || if (typeForm.value.typeName?.indexOf(' ') !== -1 ||
typeForm.value.typeName == '' || typeForm.value.typeUrl == '') { typeForm.value.typeName == '' || typeForm.value.typeUrl == '') {
ElMessage({ ElMessage({
@ -114,7 +148,7 @@ const addOrUpdateType = async () => {
const res = await myAxios.post('/category/add', { const res = await myAxios.post('/category/add', {
// //
typeName: typeForm.value.typeName, typeName: typeForm.value.typeName,
typeUrl: typeForm.value.typeUrl.substring(0, 10), typeUrl: typeForm.value.typeUrl,
typeIntro: typeForm.value.typeIntro typeIntro: typeForm.value.typeIntro
}) })
if (res.data.code === 1) { if (res.data.code === 1) {
@ -155,25 +189,12 @@ const resetForm = () => {
const handleSelectionChange = (row: any) => { const handleSelectionChange = (row: any) => {
selectedItems.value = JSON.parse(JSON.stringify(row)) selectedItems.value = JSON.parse(JSON.stringify(row))
} }
// //
const handleFileUpload = (event: Event) => {
const target = event.target as HTMLInputElement;
const file = target.files?.[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
if (e.target?.result) {
typeForm.value.typeUrl = e.target.result as string; // URL
}
};
reader.readAsDataURL(file); // Data URL
}
};
const editShowForm = (index: number, row: any) => { const editShowForm = (index: number, row: any) => {
dialogVisible.value = true dialogVisible.value = true
typeForm.value = row typeForm.value = row
flag.value = 1 flag.value = 1
console.log(row) // console.log(row)
} }
// id // id
const Delete_type = async (index: number) => { const Delete_type = async (index: number) => {

View File

@ -62,12 +62,6 @@
await router.replace('/PersonalCenter') await router.replace('/PersonalCenter')
} }
} }
// const login = () => {
// // console.log(username)
// // console.log(password)
// if(username.value ==="a"&& password.value ==="1"){
// router.push("/UserManagement")
// }}
</script> </script>
<style scoped> <style scoped>

View File

@ -0,0 +1,13 @@
<template>
<div>
</div>
</template>
<script setup>
</script>
<style lang="scss" scoped>
</style>

51
src/views/test.vue Normal file
View File

@ -0,0 +1,51 @@
<template>
<div>
<div
v-for="(item, index) in items"
:key="index"
class="box"
@click="changeColor(index)"
:style="getBoxStyle(index)"
>
{{ item }}
</div>
</div>
</template>
<script>
import { ref } from 'vue';
export default {
setup() {
const items = ref(['Box 1', 'Box 2', 'Box 3']);
const currentColor = ref(null);
const changeColor = (index) => {
currentColor.value = index;
};
const getBoxStyle = (index) => ({
backgroundColor: currentColor.value === index ? 'lightblue' : 'gray'
});
return {
items,
changeColor,
getBoxStyle,
};
},
};
</script>
<style>
.box {
width: 200px;
height: 100px;
color: black;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
margin: 5px 0;
}
</style>