类别管理修改

This commit is contained in:
yuanteng 2025-01-12 10:16:36 +08:00
parent b38083540f
commit 79e674a12a
5 changed files with 53 additions and 86 deletions

View File

@ -4,8 +4,8 @@ import router from '../router'
const myAxios = axios.create({ const myAxios = axios.create({
withCredentials:true, withCredentials:true,
baseURL: 'http://localhost:9092/api' // baseURL: 'http://localhost:9092/api'
// baseURL: 'http://123.249.108.160:8888/api' //测试服务器 baseURL: 'http://123.249.108.160:8888/api' //测试服务器
}); });
// 添加请求拦截器 // 添加请求拦截器
axios.interceptors.request.use(function (config) { axios.interceptors.request.use(function (config) {

View File

@ -100,7 +100,7 @@
<el-upload <el-upload
v-model:file-list="ImgArr" v-model:file-list="ImgArr"
ref="uploadProductImg" ref="uploadProductImg"
action="#" action="#"
list-type="picture-card" list-type="picture-card"
:auto-upload="false" :auto-upload="false"
multiple="true" multiple="true"

View File

@ -3,18 +3,19 @@
<el-button type="success" @click="showForm">添加类别</el-button> <el-button type="success" @click="showForm">添加类别</el-button>
<el-button type="danger" @click="">删除类别</el-button> <el-button type="danger" @click="">删除类别</el-button>
</div> </div>
<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" v-loading="loading">
<el-form-item label="添加类别图片"> <el-form-item label="添加类别图片">
<!-- 下面的event的作用,传入当前事件对象 --> <!-- 下面的event的作用,传入当前事件对象 -->
<el-upload <el-upload
v-model:file-list="typeImg"
action="#" action="#"
list-type="picture-card" list-type="picture-card"
:auto-upload="false" :auto-upload="false"
multiple="true" multiple="true"
:on-remove="handleRemove" :on-remove="handleRemove"
@change="(event: any) => handleChange(event)" @change="(event: any) => handleChange(event)"
:on-exceed="ExceedTypeImg"
limit="1" > limit="1" >
<el-icon> <el-icon>
<Plus /> <Plus />
@ -31,7 +32,7 @@
<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>
<el-button type="primary" @click="addOrUpdateType"> <el-button type="primary" @click="addOrUpdateType" :disabled="submitable">
提交 提交
</el-button> </el-button>
</div> </div>
@ -65,12 +66,17 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ElMessage ,type UploadProps} from 'element-plus'; import { ElMessage, type UploadProps, type UploadUserFile} from 'element-plus';
import { ErrorInfo, SuccessInfo } from '@/utils/messageInfo';
import { onMounted, ref } from 'vue' import { onMounted, ref } from 'vue'
import myAxios from '@/api/myAxios'; import myAxios from '@/api/myAxios';
const fileSimple = ref() // const fileSimple = ref() //
const selectedItems = ref([]) const selectedItems = ref([])
const dialogVisible = ref(false) const dialogVisible = ref(false)
const submitable = ref(true) //
const loading = ref(false) //
const typeImg: any = ref<UploadUserFile[]>([]) //
// const imgMap = new Map() //map
// //
const typeForm = ref({ const typeForm = ref({
id: 0, id: 0,
@ -100,6 +106,7 @@ const getTypeList = async () => {
//flag //flag
const handleChange = async (file: any) => { const handleChange = async (file: any) => {
fileSimple.value = file fileSimple.value = file
loading.value = true
let formData = new FormData() // FormData let formData = new FormData() // FormData
formData.append("file", fileSimple.value.raw) //fileSimple.value.raw formData formData.append("file", fileSimple.value.raw) //fileSimple.value.raw formData
const res = await myAxios({ // const res = await myAxios({ //
@ -114,15 +121,28 @@ const handleChange = async (file: any) => {
} }
}) })
if ( res.data.code === 1) { if ( res.data.code === 1) {
loading.value = false
SuccessInfo('上传成功')
submitable.value = false
typeForm.value.typeUrl = res.data.data typeForm.value.typeUrl = res.data.data
} else {
ErrorInfo(res.data.message)
} }
} }
// -- //
const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => { const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
console.log(uploadFile, uploadFiles) console.log(uploadFile, uploadFiles)
// typeForm.value.typeUrl = ''
typeImg.value.splice(0,typeImg.value.length) //
submitable.value = true //
}
const ExceedTypeImg: UploadProps['onExceed'] = (files) => {
} }
// //
const showForm = async () => { const showForm = async () => {
resetForm()
typeImg.value.splice(0,typeImg.value.length)
dialogVisible.value = true; dialogVisible.value = true;
flag.value = 0 flag.value = 0
} }
@ -191,10 +211,14 @@ const handleSelectionChange = (row: any) => {
} }
// //
const editShowForm = (index: number, row: any) => { const editShowForm = (index: number, row: any) => {
typeImg.value.splice(0,typeImg.value.length) //
typeImg.value.push({
url: row.typeUrl
})
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

@ -21,14 +21,14 @@
</el-form-item> </el-form-item>
<div style="margin: 10px 0; text-align: right"> <div style="margin: 10px 0; text-align: right">
<div style="display: block; <div style="display: block;
font-size: 15px; font-size: 15px;
width: 80%; width: 80%;
margin: 50px auto 0 auto; margin: 50px auto 0 auto;
text-align: center; text-align: center;
border-radius: 20px; border-radius: 20px;
background-color: rgb(172, 115, 82); background-color: rgb(172, 115, 82);
line-height: 40px; line-height: 40px;
" @click="Login">登录</div> " @click="Login">登录</div>
</div> </div>
</el-form> </el-form>
</div> </div>
@ -37,8 +37,9 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {ref, reactive, onMounted} from 'vue' import { ref } from 'vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { SuccessInfo, ErrorInfo, WarnInfo, CommInfo } from '@/utils/messageInfo';
import {useRouter} from 'vue-router' import {useRouter} from 'vue-router'
import myAxios from '@/api/myAxios'; import myAxios from '@/api/myAxios';
import { userStore } from '../store/userStore'; import { userStore } from '../store/userStore';
@ -53,24 +54,22 @@
const Login = async ()=>{ const Login = async ()=>{
if(username.value === '' || password.value === '') { if(username.value === '' || password.value === '') {
ElMessage.error('检查账号或密码是否成功填写') ErrorInfo('检查账号或密码是否成功填写')
return; return;
} }
const res: any = await myAxios.post("/user/login",{ const res: any = await myAxios.post("/user/login",{
userAccount: username.value, userAccount: username.value,
userPassword: password.value userPassword: password.value
}) })
console.log(res.data) // console.log(res.data)
if(res.data.code === 1 && res ?.data) { if(res.data.code === 1 && res ?.data) {
SuccessInfo('登陆成功')
//pinia //pinia
await store.getLoginUser(res.data.data) await store.getLoginUser(res.data.data)
// //
await router.replace('/PersonalCenter') await router.replace('/PersonalCenter')
} else { } else {
ElMessage({ WarnInfo(res.data.message)
type: 'warning',
message: res.data.message
})
return; // return; //
} }
} }

View File

@ -1,69 +1,13 @@
<template> <template>
<el-upload <button @click="test()">123213</button>
v-model:file-list="fileList"
action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
list-type="picture-card"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
>
<el-icon><Plus /></el-icon>
</el-upload>
<el-dialog v-model="dialogVisible">
<img w-full :src="dialogImageUrl" alt="Preview Image" />
</el-dialog>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from 'vue' const weekDay = function(time: string) {
import { Plus } from '@element-plus/icons-vue' let datelist = ['周日','周一','周二','周三','周四','周五','周六',]
return datelist[new Date(time).getDay()];
import type { UploadProps, UploadUserFile } from 'element-plus'
const fileList = ref<UploadUserFile[]>([
{
name: 'food.jpeg',
url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100',
},
{
name: 'plant-1.png',
url: '/images/plant-1.png',
},
{
name: 'food.jpeg',
url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100',
},
{
name: 'plant-2.png',
url: '/images/plant-2.png',
},
{
name: 'food.jpeg',
url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100',
},
{
name: 'figure-1.png',
url: '/images/figure-1.png',
},
{
name: 'food.jpeg',
url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100',
},
{
name: 'figure-2.png',
url: '/images/figure-2.png',
},
])
const dialogImageUrl = ref('')
const dialogVisible = ref(false)
const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => {
console.log(uploadFile, uploadFiles)
} }
const test =()=>{
const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => { console.log(weekDay('2025-1-8'));
dialogImageUrl.value = uploadFile.url!
dialogVisible.value = true
} }
</script> </script>