商品信息管理页面的功能项对接后台,商品分类设置功能开发(新增,修改)

This commit is contained in:
2090205686@qq.com 2025-06-09 18:49:32 +08:00
parent beb8d79eaa
commit e3ced12a92
10 changed files with 1313 additions and 300 deletions

View File

@ -5,5 +5,5 @@ VITE_APP_TITLE = 运营云后台管理系统
VITE_APP_ENV = 'development' VITE_APP_ENV = 'development'
# 开发环境 # 开发环境
VITE_APP_BASE_API = 'http://192.168.18.99:8080' VITE_APP_BASE_API = 'http://192.168.18.151:8080'
VITE_APP_PLATFORM = 'http://localhost:9000/platform' VITE_APP_PLATFORM = 'http://localhost:9000/platform'

View File

@ -8,6 +8,14 @@ export function getGoodManageInfo(query) {
params: query params: query
}) })
} }
// 获取商品列表页顶部tab中的数据
export function getGoodManageCount(query) {
return request({
url: '/goods/goodInfoManage/getGoodManageCount',
method: 'get',
params: query
})
}
// 获取商品分类列表 // 获取商品分类列表
export function getGoodType(query) { export function getGoodType(query) {
@ -35,19 +43,18 @@ export function goodEdit(data) {
}) })
} }
// 商品删除 // 商品删除
export function goodDelete(data) { export function goodDelete(id) {
return request({ return request({
url: '/goods/business/category/remove', url: '/goods/goodInfoManage/deleteGoodInfo/id=' + id,
method: 'post', method: 'delete',
data: data
}) })
} }
// 商品上下架 // 商品上下架
export function goodUpAndDown(data) { export function goodUpAndDown(data) {
return request({ return request({
url: '/goods/goodInfoManage/goodEdit', url: '/goods/goodInfoManage/goodOnSale',
method: 'post', method: 'put',
data: data data: data
}) })
} }
@ -67,3 +74,21 @@ export function getActiveInfos() {
method: 'get' method: 'get'
}) })
} }
// 获取商品分类列表
export function getGoodCategoryInfo(query) {
return request({
url: '/goods/business/category/list',
method: 'get',
params: query
})
}
// 新增商品分类
export function categoryAdd(data) {
return request({
url: '/goods/business/category/add',
method: 'post',
data: data
})
}

View File

@ -185,6 +185,10 @@ const props = defineProps({
type: Function, type: Function,
default: () => "", default: () => "",
}, },
rowkey: {
type: String,
default: "",
},
}); });
const emit = defineEmits([ const emit = defineEmits([
@ -227,7 +231,7 @@ const handleCurrentChange = (val) => {
// //
const handleSelectionChange = (selection) => { const handleSelectionChange = (selection) => {
const selectedIds = selection.map((row) => row.id); const selectedIds = selection.map((row) => props.rowkey == "" ? row.id : row[props.rowkey]);
emit("selection-change", selection, selectedIds); emit("selection-change", selection, selectedIds);
}; };

View File

@ -12,16 +12,16 @@
class="demo-form-inline" class="demo-form-inline"
:label-width="'auto'" :label-width="'auto'"
> >
<el-form-item label="分类名称" prop="categoryName"> <el-form-item label="分类名称" prop="name">
<el-input <el-input
v-model="formInline.categoryName" v-model="formInline.name"
placeholder="请输入分类名称" placeholder="请输入分类名称"
clearable clearable
/> />
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="categoryStatus"> <el-form-item label="状态" prop="status">
<el-select <el-select
v-model="formInline.categoryStatus" v-model="formInline.status"
placeholder="请选择" placeholder="请选择"
clearable clearable
> >
@ -33,7 +33,7 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<br> <br />
<el-form-item <el-form-item
label="添加时间" label="添加时间"
prop="startDate" prop="startDate"
@ -85,14 +85,12 @@
icon="delete" icon="delete"
@click="batchDelete" @click="batchDelete"
:disabled="btnStatus" :disabled="btnStatus"
style="margin-right: 10px" style="margin-right: 0px"
>批量删除</el-button >批量删除</el-button
> >
<router-link to="/goods/addGoods"> <el-button type="primary" icon="plus" @click="addCategory"
<el-button type="primary" icon="plus" @click="onSubmit"
>添加分类</el-button >添加分类</el-button
> >
</router-link>
</div> </div>
<tableComponent <tableComponent
:table-data="tableData" :table-data="tableData"
@ -107,6 +105,7 @@
:current-page="formInline.current" :current-page="formInline.current"
:page-size="formInline.size" :page-size="formInline.size"
:showSort="true" :showSort="true"
:rowkey="'goodId'"
> >
<!-- 自定义-状态 --> <!-- 自定义-状态 -->
<template #goodsUrl="slotProps"> <template #goodsUrl="slotProps">
@ -120,8 +119,8 @@
</template> </template>
<!-- 自定义-状态 --> <!-- 自定义-状态 -->
<template #categoryStatus="slotProps"> <template #status="slotProps">
<span v-if="slotProps.row.categoryStatus == '已启用'" class="color-green" <span v-if="slotProps.row.status == 1" class="color-green"
>已启用</span >已启用</span
> >
<span v-else class="color-gray">未启用</span> <span v-else class="color-gray">未启用</span>
@ -129,72 +128,95 @@
<!-- 自定义-操作 --> <!-- 自定义-操作 -->
<template #action="slotProps"> <template #action="slotProps">
<el-tooltip effect="dark" placement="bottom-end"> <el-button
<template #content> text
<div class="custom-tooltip-content"> v-if="slotProps.row.status == 2"
<el-icon class="el-button-custom"
class="el-icon-custom"
@click="seeDetails(slotProps.row)" @click="seeDetails(slotProps.row)"
>启用</el-button
> >
<View /> <el-button
</el-icon> text
<el-icon v-if="slotProps.row.status == 1"
class="el-icon-custom" class="el-button-custom"
@click="toUpload(slotProps.row)" @click="seeDetails(slotProps.row)"
>禁用</el-button
> >
<Upload /> <el-button
</el-icon> text
<el-icon class="el-button-custom"
class="el-icon-custom"
@click="toDownload(slotProps.row)"
>
<Download />
</el-icon>
<el-icon
class="el-icon-custom"
@click="handleEdit(slotProps.row)" @click="handleEdit(slotProps.row)"
>编辑</el-button
> >
<Edit /> <el-button
</el-icon> text
<el-icon class="el-button-delete"
class="el-icon-custom"
@click="handleDelete(slotProps.row)" @click="handleDelete(slotProps.row)"
>删除</el-button
> >
<Delete />
</el-icon>
</div>
</template>
<span class="el-dropdown-link">
<el-icon>
<More />
</el-icon>
</span>
</el-tooltip>
</template> </template>
</tableComponent> </tableComponent>
</div> </div>
</div> </div>
<!-- 添加分类 -->
<el-dialog v-model="dialogFormVisible" :title="dialogTitle" width="500">
<el-form
:model="dialogForm"
:label-width="'80'"
:rules="dialogFormRules"
ref="dialogRef"
>
<el-form-item label="分类名称" prop="name">
<el-input v-model="dialogForm.name" autocomplete="off" placeholder="请输入分类名称"/>
</el-form-item>
<el-form-item label="父级分类" prop="parentId">
<el-cascader
v-model="dialogForm.parentId"
:options="goodsOptions"
:props="cascaderProps"
placeholder="请选择父级分类"
clearable
style="width: 100%"
/>
</el-form-item>
<el-form-item label="是否禁用" prop="status" required>
<el-radio-group v-model="dialogForm.status" style="margin-top: -3px">
<el-radio value="1" size="large">启用类别</el-radio>
<el-radio value="2" size="large">禁用类别</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="onSaveCategory">
确认添加
</el-button>
<el-button @click="cancelDialog">取消</el-button>
</div>
</template>
</el-dialog>
</div> </div>
</template> </template>
<script setup> <script setup>
import { ref, reactive, computed, onMounted, onBeforeUnmount } from "vue"; import { ref, reactive, computed, onMounted, onBeforeUnmount } from "vue";
import tableComponent from "@/components/tableComponent.vue"; import tableComponent from "@/components/tableComponent.vue";
import Mock from "mockjs"; import Mock from "mockjs";
import { getGoodManageInfo } from "@/api/goods/info"; import { getGoodCategoryInfo, getGoodType, categoryAdd } from "@/api/goods/info";
import { ca } from "element-plus/es/locales.mjs"; import { ca } from "element-plus/es/locales.mjs";
const { proxy } = getCurrentInstance()
const formInline = reactive({ const formInline = reactive({
categoryName: "", name: "",
categoryStatus: "", status: "",
startDate: "", startDate: "",
endDate: "", endDate: "",
current: 1, current: 1,
size: 10, size: 10,
}); });
const statusList = ref([ const statusList = ref([
{ name: "未启用", id: '0'}, { name: "未启用", id: "2" },
{ name: "已启用", id: '1' }, { name: "已启用", id: "1" },
]); ]);
// //
const disableStartDate = (time) => { const disableStartDate = (time) => {
@ -215,7 +237,7 @@ const searchForm = ref(null);
const onSubmit = () => { const onSubmit = () => {
console.log("submit!"); console.log("submit!");
formInline.current = 1; formInline.current = 1;
formInline.categoryStatus = formInline.categoryStatus == undefined ? '' : formInline.categoryStatus; formInline.status = formInline.status == undefined ? "" : formInline.status;
console.log(formInline); console.log(formInline);
loadData(); loadData();
}; };
@ -236,10 +258,10 @@ let nowClickRow = ref({});
const columns = ref([]); const columns = ref([]);
const columns1 = ref([ const columns1 = ref([
{ prop: "id", label: "ID" }, { prop: "id", label: "ID" },
{ prop: "categoryName", label: "类别" }, { prop: "name", label: "类别" },
{ prop: "addTime", label: "添加时间" }, { prop: "createTime", label: "添加时间" },
{ prop: "categoryStatus", label: "状态", slotName: "categoryStatus" }, { prop: "status", label: "状态", slotName: "status" },
{ prop: "action", label: "操作", slotName: "action" }, { prop: "action", label: "操作", slotName: "action", width: 150 },
]); ]);
// //
@ -271,9 +293,9 @@ const generateMockData = () => {
"list|10": [ "list|10": [
{ {
"id|+1": 10000, "id|+1": 10000,
categoryName: '@pick(["种子", "化肥", "农药"])', // name: '@pick(["种子", "化肥", "农药"])', //
addTime: "@datetime", // createTime: "@datetime", //
categoryStatus: '@pick(["已启用", "未启用"])', // status: "@pick([1, 2])", //
}, },
], ],
}).list; }).list;
@ -281,18 +303,18 @@ const generateMockData = () => {
// //
const loadData = async () => { const loadData = async () => {
tableLoading.value = true; tableLoading.value = true;
tableData.value = generateMockData(); // tableData.value = generateMockData();
tableTotal.value = tableData.value.length; // tableTotal.value = tableData.value.length;
// try { try {
// let response = await getGoodManageInfo(formInline); let response = await getGoodCategoryInfo(formInline);
// console.log(response); console.log(response);
// if (response.code == 200) { if (response.code == 200) {
// tableData.value = response.data.records; tableData.value = response.data.records;
// tableTotal.value = response.data.total; tableTotal.value = response.data.total;
// } }
// } catch (error) { } catch (error) {
// console.log(error); console.log(error);
// } }
tableLoading.value = false; tableLoading.value = false;
}; };
@ -319,12 +341,6 @@ const seeDetails = (row) => {
nowClickRow.value = row; nowClickRow.value = row;
console.log("要查看详情的行:", row); console.log("要查看详情的行:", row);
}; };
const toUpload = () => {
console.log("向上移动:");
};
const toDownload = () => {
console.log("向下移动:");
};
// //
const handleEdit = (row) => { const handleEdit = (row) => {
nowClickRow.value = row; nowClickRow.value = row;
@ -340,6 +356,87 @@ const batchDelete = () => {
console.log("要删除的行:", selectedIds.value); console.log("要删除的行:", selectedIds.value);
}; };
const dialogFormVisible = ref(false);
const dialogRef = ref(null);
const dialogTitle = ref("添加分类");
const dialogForm = reactive({
type: null, //1->,2->3->,4->
name: "", //
parentId: [], //id
level: "", //
sort: "", //
status: "1", //(1- 2-)
});
const dialogFormRules = ref({
name: [
{ required: true, message: "请输入分类名称", trigger: "blur" },
{ min: 2, max: 10, message: "长度在 2 到 10 个字符", trigger: "blur" },
],
parentId: [
{ required: true, message: "请选择父级分类", trigger: ["blur", "change"] },
],
});
//
const cascaderProps = ref({
label: "name", //
value: "id", //
children: "children", //
emitPath: true,
expandTrigger: "hover",
});
const goodsOptions = ref([]);
const getGoodTypeList = async () => {
try {
let response = await getGoodType();
console.log(response);
if (response.code == 200) {
goodsOptions.value = response.data;
}
} catch (error) {
console.log(error);
}
};
const onSaveCategory = async () => {
console.log("保存分类");
console.log(dialogForm);
await dialogRef.value.validate(async (valid, fields) => {
if (valid) {
try {
console.log("验证通过!");
proxy.$modal.loading("正在添加中...")
let param = {...dialogForm};
param.parentId = dialogForm.parentId.join(",");
let response = await categoryAdd(param);
proxy.$modal.closeLoading()
if (response.code == 200) {
console.log(response);
dialogFormVisible.value = false;
ElMessage.success(response.msg);
loadData();
} else {
ElMessage.error(response.msg);
}
} catch (error) {
proxy.$modal.closeLoading()
}
}
});
};
//
const addCategory = () => {
console.log("添加分类");
dialogFormVisible.value = true;
};
const EditCategory = () => {
console.log("编辑分类");
dialogTitle.value = "编辑分类";
dialogFormVisible.value = true;
};
const cancelDialog = () => {
console.log("取消");
dialogFormVisible.value = false;
};
const titleRef = ref(null); const titleRef = ref(null);
const searchBarRef = ref(null); const searchBarRef = ref(null);
const tableViewportHeight = ref(0); const tableViewportHeight = ref(0);
@ -364,6 +461,7 @@ const calculateTableHeight = () => {
onMounted(() => { onMounted(() => {
columns.value = columns1.value; columns.value = columns1.value;
loadData(); loadData();
getGoodTypeList();
calculateTableHeight(); calculateTableHeight();

View File

@ -204,6 +204,7 @@ import myUploadVideo from "@/components/myUploadVideo.vue";
import { getGoodType, goodAdd, getActiveInfos } from "@/api/goods/info"; import { getGoodType, goodAdd, getActiveInfos } from "@/api/goods/info";
import { getRegion } from "@/api/common"; import { getRegion } from "@/api/common";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import areaList from "./areaList";
const formRef = ref(null) const formRef = ref(null)
const formInline = reactive({ const formInline = reactive({
@ -443,46 +444,15 @@ const selectedAddress = ref([]);
const detailAddress = ref(''); const detailAddress = ref('');
// //
const cascaderProps = ref({ const cascaderProps = ref({
value: 'name', // label: 'areaName', //
label: 'name', // value: 'areaCode', //
children: 'children' // children: 'areaChildVOS', //
emitPath: true,
expandTrigger: 'hover',
}); });
// //
const addressOptions = ref([ const addressOptions = ref([]);
{ addressOptions.value = areaList.data;
name: '云南省',
children: [
{
name: '昆明市',
children: [
{ name: '五华区' },
{ name: '盘龙区' },
{ name: '呈贡区' }
]
},
{
name: '曲靖市',
children: [
{ name: '麒麟区' },
{ name: '沾益区' }
]
}
]
},
{
name: '广东省',
children: [
{
name: '广州市',
children: [
{ name: '天河区' },
{ name: '越秀区' }
]
}
]
}
// ...
]);
// //
const isSafeguardSelected = computed({ const isSafeguardSelected = computed({

View File

@ -0,0 +1,792 @@
export default {
"code": 200,
"msg": null,
"data": [
{
"id": "3",
"areaName": "耿马傣族佤族自治县",
"parentId": "530900",
"areaCode": "530926",
"level": 2,
"areaChildVOS": [
{
"id": "4",
"areaName": "耿马镇",
"parentId": "530926",
"areaCode": "530926100",
"level": 3,
"areaChildVOS": [
{
"id": "16",
"areaName": "甘东社区",
"parentId": "530926100",
"areaCode": "5309261001",
"level": 4,
"areaChildVOS": []
},
{
"id": "17",
"areaName": "白马社区",
"parentId": "530926100",
"areaCode": "5309261002",
"level": 4,
"areaChildVOS": []
},
{
"id": "18",
"areaName": "白塔社区",
"parentId": "530926100",
"areaCode": "5309261003",
"level": 4,
"areaChildVOS": []
},
{
"id": "19",
"areaName": "团结村",
"parentId": "530926100",
"areaCode": "5309261004",
"level": 4,
"areaChildVOS": []
},
{
"id": "20",
"areaName": "新城村",
"parentId": "530926100",
"areaCode": "5309261005",
"level": 4,
"areaChildVOS": []
},
{
"id": "21",
"areaName": "芒蚌村",
"parentId": "530926100",
"areaCode": "5309261006",
"level": 4,
"areaChildVOS": []
},
{
"id": "22",
"areaName": "芒国村",
"parentId": "530926100",
"areaCode": "5309261007",
"level": 4,
"areaChildVOS": []
},
{
"id": "23",
"areaName": "复兴村",
"parentId": "530926100",
"areaCode": "5309261008",
"level": 4,
"areaChildVOS": []
},
{
"id": "24",
"areaName": "允楞村",
"parentId": "530926100",
"areaCode": "5309261009",
"level": 4,
"areaChildVOS": []
},
{
"id": "25",
"areaName": "石灰窑村",
"parentId": "530926100",
"areaCode": "53092610010",
"level": 4,
"areaChildVOS": []
},
{
"id": "26",
"areaName": "南木弄村",
"parentId": "530926100",
"areaCode": "53092610011",
"level": 4,
"areaChildVOS": []
},
{
"id": "27",
"areaName": "允捧村",
"parentId": "530926100",
"areaCode": "53092610012",
"level": 4,
"areaChildVOS": []
},
{
"id": "28",
"areaName": "菜籽地村",
"parentId": "530926100",
"areaCode": "53092610013",
"level": 4,
"areaChildVOS": []
},
{
"id": "29",
"areaName": "弄巴村",
"parentId": "530926100",
"areaCode": "53092610014",
"level": 4,
"areaChildVOS": []
}
]
},
{
"id": "5",
"areaName": "勐永镇",
"parentId": "530926",
"areaCode": "530926101",
"level": 3,
"areaChildVOS": [
{
"id": "30",
"areaName": "勐永村",
"parentId": "530926101",
"areaCode": "5309261011",
"level": 4,
"areaChildVOS": []
},
{
"id": "31",
"areaName": "新和村",
"parentId": "530926101",
"areaCode": "5309261012",
"level": 4,
"areaChildVOS": []
},
{
"id": "32",
"areaName": "芒来村",
"parentId": "530926101",
"areaCode": "5309261013",
"level": 4,
"areaChildVOS": []
},
{
"id": "33",
"areaName": "芒佑村",
"parentId": "530926101",
"areaCode": "5309261014",
"level": 4,
"areaChildVOS": []
},
{
"id": "34",
"areaName": "芒糯村",
"parentId": "530926101",
"areaCode": "5309261015",
"level": 4,
"areaChildVOS": []
},
{
"id": "35",
"areaName": "帮令村",
"parentId": "530926101",
"areaCode": "5309261016",
"level": 4,
"areaChildVOS": []
},
{
"id": "36",
"areaName": "香竹林村",
"parentId": "530926101",
"areaCode": "5309261017",
"level": 4,
"areaChildVOS": []
},
{
"id": "37",
"areaName": "光木林村",
"parentId": "530926101",
"areaCode": "5309261018",
"level": 4,
"areaChildVOS": []
}
]
},
{
"id": "6",
"areaName": "勐撒镇",
"parentId": "530926",
"areaCode": "530926102",
"level": 3,
"areaChildVOS": [
{
"id": "38",
"areaName": "丙令村",
"parentId": "530926102",
"areaCode": "5309261021",
"level": 4,
"areaChildVOS": []
},
{
"id": "39",
"areaName": "芒茂村",
"parentId": "530926102",
"areaCode": "5309261022",
"level": 4,
"areaChildVOS": []
},
{
"id": "40",
"areaName": "城子村",
"parentId": "530926102",
"areaCode": "5309261023",
"level": 4,
"areaChildVOS": []
},
{
"id": "41",
"areaName": "芒枕村",
"parentId": "530926102",
"areaCode": "5309261024",
"level": 4,
"areaChildVOS": []
},
{
"id": "42",
"areaName": "箐门口村",
"parentId": "530926102",
"areaCode": "5309261025",
"level": 4,
"areaChildVOS": []
},
{
"id": "43",
"areaName": "班必村",
"parentId": "530926102",
"areaCode": "5309261026",
"level": 4,
"areaChildVOS": []
},
{
"id": "44",
"areaName": "翁达村",
"parentId": "530926102",
"areaCode": "5309261027",
"level": 4,
"areaChildVOS": []
},
{
"id": "45",
"areaName": "琅琊村",
"parentId": "530926102",
"areaCode": "5309261028",
"level": 4,
"areaChildVOS": []
},
{
"id": "46",
"areaName": "户肯村",
"parentId": "530926102",
"areaCode": "5309261029",
"level": 4,
"areaChildVOS": []
}
]
},
{
"id": "7",
"areaName": "孟定镇",
"parentId": "530926",
"areaCode": "530926103",
"level": 3,
"areaChildVOS": [
{
"id": "47",
"areaName": "城关村",
"parentId": "530926103",
"areaCode": "5309261031",
"level": 4,
"areaChildVOS": []
},
{
"id": "48",
"areaName": "下城村",
"parentId": "530926103",
"areaCode": "5309261032",
"level": 4,
"areaChildVOS": []
},
{
"id": "49",
"areaName": "罕宏村",
"parentId": "530926103",
"areaCode": "5309261033",
"level": 4,
"areaChildVOS": []
},
{
"id": "50",
"areaName": "贺海村",
"parentId": "530926103",
"areaCode": "5309261034",
"level": 4,
"areaChildVOS": []
},
{
"id": "51",
"areaName": "遮哈村",
"parentId": "530926103",
"areaCode": "5309261035",
"level": 4,
"areaChildVOS": []
},
{
"id": "52",
"areaName": "下坝村",
"parentId": "530926103",
"areaCode": "5309261036",
"level": 4,
"areaChildVOS": []
},
{
"id": "53",
"areaName": "河西村",
"parentId": "530926103",
"areaCode": "5309261037",
"level": 4,
"areaChildVOS": []
},
{
"id": "54",
"areaName": "新寨村",
"parentId": "530926103",
"areaCode": "5309261038",
"level": 4,
"areaChildVOS": []
},
{
"id": "55",
"areaName": "景信村",
"parentId": "530926103",
"areaCode": "5309261039",
"level": 4,
"areaChildVOS": []
},
{
"id": "56",
"areaName": "糯峨村",
"parentId": "530926103",
"areaCode": "5309261040",
"level": 4,
"areaChildVOS": []
},
{
"id": "57",
"areaName": "芒美村",
"parentId": "530926103",
"areaCode": "5309261041",
"level": 4,
"areaChildVOS": []
},
{
"id": "58",
"areaName": "邱山村",
"parentId": "530926103",
"areaCode": "5309261042",
"level": 4,
"areaChildVOS": []
},
{
"id": "59",
"areaName": "德龙村",
"parentId": "530926103",
"areaCode": "5309261043",
"level": 4,
"areaChildVOS": []
},
{
"id": "60",
"areaName": "芒撒村",
"parentId": "530926103",
"areaCode": "5309261044",
"level": 4,
"areaChildVOS": []
},
{
"id": "61",
"areaName": "崇岗村",
"parentId": "530926103",
"areaCode": "5309261045",
"level": 4,
"areaChildVOS": []
},
{
"id": "62",
"areaName": "芒艾村",
"parentId": "530926103",
"areaCode": "5309261046",
"level": 4,
"areaChildVOS": []
},
{
"id": "63",
"areaName": "色树坝村",
"parentId": "530926103",
"areaCode": "5309261047",
"level": 4,
"areaChildVOS": []
},
{
"id": "64",
"areaName": "尖坪村",
"parentId": "530926103",
"areaCode": "5309261048",
"level": 4,
"areaChildVOS": []
},
{
"id": "65",
"areaName": "山头寨村",
"parentId": "530926103",
"areaCode": "5309261049",
"level": 4,
"areaChildVOS": []
},
{
"id": "66",
"areaName": "班幸村",
"parentId": "530926103",
"areaCode": "5309261050",
"level": 4,
"areaChildVOS": []
},
{
"id": "67",
"areaName": "清水河村",
"parentId": "530926103",
"areaCode": "5309261051",
"level": 4,
"areaChildVOS": []
},
{
"id": "68",
"areaName": "尖山村",
"parentId": "530926103",
"areaCode": "5309261052",
"level": 4,
"areaChildVOS": []
},
{
"id": "69",
"areaName": "大水井村",
"parentId": "530926103",
"areaCode": "5309261053",
"level": 4,
"areaChildVOS": []
},
{
"id": "70",
"areaName": "和顺新村",
"parentId": "530926103",
"areaCode": "5309261054",
"level": 4,
"areaChildVOS": []
},
{
"id": "71",
"areaName": "沙源新村",
"parentId": "530926103",
"areaCode": "5309261055",
"level": 4,
"areaChildVOS": []
}
]
},
{
"id": "8",
"areaName": "大兴乡",
"parentId": "530926",
"areaCode": "530926200",
"level": 3,
"areaChildVOS": [
{
"id": "72",
"areaName": "大兴村",
"parentId": "530926200",
"areaCode": "5309262001",
"level": 4,
"areaChildVOS": []
},
{
"id": "73",
"areaName": "岩榴村",
"parentId": "530926200",
"areaCode": "5309262002",
"level": 4,
"areaChildVOS": []
},
{
"id": "74",
"areaName": "永胜村",
"parentId": "530926200",
"areaCode": "5309262003",
"level": 4,
"areaChildVOS": []
},
{
"id": "75",
"areaName": "户肯村",
"parentId": "530926200",
"areaCode": "5309262004",
"level": 4,
"areaChildVOS": []
},
{
"id": "76",
"areaName": "龚家寨村",
"parentId": "530926200",
"areaCode": "5309262005",
"level": 4,
"areaChildVOS": []
},
{
"id": "77",
"areaName": "班坝村",
"parentId": "530926200",
"areaCode": "5309262006",
"level": 4,
"areaChildVOS": []
}
]
},
{
"id": "9",
"areaName": "芒洪拉祜族布朗族乡",
"parentId": "530926",
"areaCode": "530926201",
"level": 3,
"areaChildVOS": [
{
"id": "78",
"areaName": "芒洪村",
"parentId": "530926201",
"areaCode": "5309262011",
"level": 4,
"areaChildVOS": []
},
{
"id": "79",
"areaName": "科且村",
"parentId": "530926201",
"areaCode": "5309262012",
"level": 4,
"areaChildVOS": []
},
{
"id": "80",
"areaName": "安雅村",
"parentId": "530926201",
"areaCode": "5309262013",
"level": 4,
"areaChildVOS": []
},
{
"id": "81",
"areaName": "新联村",
"parentId": "530926201",
"areaCode": "5309262014",
"level": 4,
"areaChildVOS": []
},
{
"id": "82",
"areaName": "马厂村",
"parentId": "530926201",
"areaCode": "5309262015",
"level": 4,
"areaChildVOS": []
}
]
},
{
"id": "10",
"areaName": "四排山乡",
"parentId": "530926",
"areaCode": "530926202",
"level": 3,
"areaChildVOS": [
{
"id": "83",
"areaName": "老寨村",
"parentId": "530926202",
"areaCode": "5309262021",
"level": 4,
"areaChildVOS": []
},
{
"id": "84",
"areaName": "关弄村",
"parentId": "530926202",
"areaCode": "5309262022",
"level": 4,
"areaChildVOS": []
},
{
"id": "85",
"areaName": "芒关村",
"parentId": "530926202",
"areaCode": "5309262023",
"level": 4,
"areaChildVOS": []
},
{
"id": "86",
"areaName": "芒翁村",
"parentId": "530926202",
"areaCode": "5309262024",
"level": 4,
"areaChildVOS": []
},
{
"id": "87",
"areaName": "梁子寨村",
"parentId": "530926202",
"areaCode": "5309262025",
"level": 4,
"areaChildVOS": []
},
{
"id": "88",
"areaName": "石佛洞村",
"parentId": "530926202",
"areaCode": "5309262026",
"level": 4,
"areaChildVOS": []
},
{
"id": "89",
"areaName": "东坡村",
"parentId": "530926202",
"areaCode": "5309262027",
"level": 4,
"areaChildVOS": []
},
{
"id": "90",
"areaName": "班康村",
"parentId": "530926202",
"areaCode": "5309262028",
"level": 4,
"areaChildVOS": []
}
]
},
{
"id": "11",
"areaName": "贺派乡",
"parentId": "530926",
"areaCode": "530926203",
"level": 3,
"areaChildVOS": [
{
"id": "91",
"areaName": "贺派村",
"parentId": "530926203",
"areaCode": "5309262031",
"level": 4,
"areaChildVOS": []
},
{
"id": "92",
"areaName": "芒抗村",
"parentId": "530926203",
"areaCode": "5309262032",
"level": 4,
"areaChildVOS": []
},
{
"id": "93",
"areaName": "水平村",
"parentId": "530926203",
"areaCode": "5309262033",
"level": 4,
"areaChildVOS": []
},
{
"id": "94",
"areaName": "落阳村",
"parentId": "530926203",
"areaCode": "5309262034",
"level": 4,
"areaChildVOS": []
},
{
"id": "95",
"areaName": "崩弄村",
"parentId": "530926203",
"areaCode": "5309262035",
"level": 4,
"areaChildVOS": []
},
{
"id": "96",
"areaName": "芒底村",
"parentId": "530926203",
"areaCode": "5309262036",
"level": 4,
"areaChildVOS": []
},
{
"id": "97",
"areaName": "帮卖村",
"parentId": "530926203",
"areaCode": "5309262037",
"level": 4,
"areaChildVOS": []
}
]
},
{
"id": "12",
"areaName": "勐简乡",
"parentId": "530926",
"areaCode": "530926204",
"level": 3,
"areaChildVOS": [
{
"id": "98",
"areaName": "勐简村",
"parentId": "530926204",
"areaCode": "5309262041",
"level": 4,
"areaChildVOS": []
},
{
"id": "99",
"areaName": "班望村",
"parentId": "530926204",
"areaCode": "5309262042",
"level": 4,
"areaChildVOS": []
},
{
"id": "100",
"areaName": "迎们寨村",
"parentId": "530926204",
"areaCode": "5309262043",
"level": 4,
"areaChildVOS": []
},
{
"id": "101",
"areaName": "大寨村",
"parentId": "530926204",
"areaCode": "5309262044",
"level": 4,
"areaChildVOS": []
},
{
"id": "102",
"areaName": "老厂村",
"parentId": "530926204",
"areaCode": "5309262045",
"level": 4,
"areaChildVOS": []
}
]
}
]
}
]
}

View File

@ -205,6 +205,8 @@ import myUploadVideo from "@/components/myUploadVideo.vue";
import { getGoodType, goodEdit, getGoodInfo, getActiveInfos } from "@/api/goods/info"; import { getGoodType, goodEdit, getGoodInfo, getActiveInfos } from "@/api/goods/info";
import { getRegion } from "@/api/common"; import { getRegion } from "@/api/common";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import areaList from "./areaList";
const route = useRoute() const route = useRoute()
const router = useRouter() const router = useRouter()
@ -433,46 +435,15 @@ const selectedAddress = ref([]);
const detailAddress = ref(''); const detailAddress = ref('');
// //
const cascaderProps = ref({ const cascaderProps = ref({
value: 'name', // label: 'areaName', //
label: 'name', // value: 'areaCode', //
children: 'children' // children: 'areaChildVOS', //
emitPath: true,
expandTrigger: 'hover',
}); });
// //
const addressOptions = ref([ const addressOptions = ref([]);
{ addressOptions.value = areaList.data;
name: '云南省',
children: [
{
name: '昆明市',
children: [
{ name: '五华区' },
{ name: '盘龙区' },
{ name: '呈贡区' }
]
},
{
name: '曲靖市',
children: [
{ name: '麒麟区' },
{ name: '沾益区' }
]
}
]
},
{
name: '广东省',
children: [
{
name: '广州市',
children: [
{ name: '天河区' },
{ name: '越秀区' }
]
}
]
}
// ...
]);
// //
const isSafeguardSelected = computed({ const isSafeguardSelected = computed({

View File

@ -7,45 +7,96 @@
<div class="search-bar-left"> <div class="search-bar-left">
<div class="order-tab" style="margin-top: -10px"> <div class="order-tab" style="margin-top: -10px">
<el-tabs v-model="activeCurrent" @tab-click="tabChange"> <el-tabs v-model="activeCurrent" @tab-click="tabChange">
<el-tab-pane v-for="t in bottomList" :key="t.id" :label="t.title + '(' + t.value + ')'" :name="t.id"> <el-tab-pane
v-for="t in bottomList"
:key="t.id"
:label="t.title + t.value"
:name="t.id"
>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
<el-form ref="searchForm" :inline="true" :model="formInline" class="demo-form-inline" :label-width="'auto'"> <el-form
ref="searchForm"
:inline="true"
:model="formInline"
class="demo-form-inline"
:label-width="'auto'"
>
<el-form-item label="商品名称" prop="goodName"> <el-form-item label="商品名称" prop="goodName">
<el-input v-model="formInline.goodName" placeholder="请输入商品名称" clearable /> <el-input
v-model="formInline.goodName"
placeholder="请输入商品名称"
clearable
/>
</el-form-item> </el-form-item>
<el-form-item label="商品分类" prop="goodCategoryId"> <el-form-item
<el-select v-model="formInline.goodCategoryId" placeholder="请选择" clearable> label="商品分类"
prop="goodCategoryId"
class="custom-form-inline"
>
<!-- <el-select v-model="formInline.goodCategoryId" placeholder="请选择" clearable>
<el-option v-for="item in goodsCategoryList" :key="item.id" :value="item.id" :label="item.name" /> <el-option v-for="item in goodsCategoryList" :key="item.id" :value="item.id" :label="item.name" />
</el-select> </el-select> -->
<el-cascader
v-model="formInline.goodCategoryId"
:options="goodsOptions"
:props="cascaderProps"
placeholder="请选择省市区"
clearable
/>
</el-form-item> </el-form-item>
<el-form-item label="商品品牌" prop="storeId"> <!-- <el-form-item label="商品品牌" prop="storeId">
<el-select v-model="formInline.storeId" placeholder="请选择" clearable> <el-select v-model="formInline.storeId" placeholder="请选择" clearable>
<el-option v-for="item in goodsBrandList" :key="item.id" :value="item.id" :label="item.name" /> <el-option v-for="item in goodsBrandList" :key="item.id" :value="item.id" :label="item.name" />
</el-select> </el-select>
</el-form-item> </el-form-item> -->
</el-form> </el-form>
</div> </div>
<div class="search-bar-right"> <div class="search-bar-right">
<el-button type="primary" icon="Search" @click="onSubmit">查询</el-button> <el-button type="primary" icon="Search" @click="onSubmit"
<el-button icon="Refresh" style="margin: 16px 0 0 0" @click="resetForm">重置</el-button> >查询</el-button
>
<el-button
icon="Refresh"
style="margin: 16px 0 0 0"
@click="resetForm"
>重置</el-button
>
</div> </div>
</div> </div>
</div> </div>
<!-- 表格 --> <!-- 表格 -->
<div class="table-cont" :style="{ height: tableViewportHeight + 'px' }"> <div class="table-cont" :style="{ height: tableViewportHeight + 'px' }">
<div class="table-toolbar"> <div class="table-toolbar">
<el-button icon="delete" @click="batchDelete" :disabled="btnStatus" <el-button
style="margin-right: 10px">批量删除</el-button> icon="delete"
@click="batchDelete"
:disabled="btnStatus"
style="margin-right: 10px"
>批量删除</el-button
>
<router-link to="/goods/goodsManage/addGoods"> <router-link to="/goods/goodsManage/addGoods">
<el-button type="primary" icon="plus" @click="onSubmit">新增商品</el-button> <el-button type="primary" icon="plus" @click="onSubmit"
>新增商品</el-button
>
</router-link> </router-link>
</div> </div>
<tableComponent :table-data="tableData" :columns="columns" :show-border="false" :show-selection="true" <tableComponent
:header-cell-class-name="getHeaderClass" @page-change="handlePaginationChange" :loading="tableLoading" :table-data="tableData"
@selection-change="handleSelectionChange" :total="tableTotal" :current-page="formInline.current" :columns="columns"
:page-size="formInline.size" :showSort="true"> :show-border="false"
:show-selection="true"
:header-cell-class-name="getHeaderClass"
@page-change="handlePaginationChange"
:loading="tableLoading"
@selection-change="handleSelectionChange"
:total="tableTotal"
:current-page="formInline.current"
:page-size="formInline.size"
:showSort="true"
:rowkey="'goodId'"
>
<!-- 自定义-图片 --> <!-- 自定义-图片 -->
<template #goodUrl="slotProps"> <template #goodUrl="slotProps">
<div class="table-cell-img-box"> <div class="table-cell-img-box">
@ -54,47 +105,64 @@
</template> </template>
<!-- 自定义 - 序号 --> <!-- 自定义 - 序号 -->
<template #sort="slotProps"> <template #sort="slotProps">
<span v-if="slotProps.row.goodPrice">{{ slotProps.row.goodPrice }}</span> <span v-if="slotProps.row.goodPrice"
>{{ slotProps.row.goodPrice }}</span
>
</template> </template>
<!-- 自定义-状态 --> <!-- 自定义-状态 -->
<template #isListed="slotProps"> <template #isListed="slotProps">
<span v-if="slotProps.row.isListed == 0" class="color-blue">待上架</span> <span v-if="slotProps.row.isListed == 0" class="color-blue"
<span v-else-if="slotProps.row.isListed == 1" class="color-black">已上架</span> >待上架</span
<span v-else-if="slotProps.row.isListed == 2" class="color-green">上架</span> >
<span v-else-if="slotProps.row.isListed == 3" class="color-red">下架</span> <span v-else-if="slotProps.row.isListed == 1" class="color-black"
<span v-else-if="slotProps.row.isListed == 4" class="color-orange">审核中</span> >已上架</span
>
<span v-else-if="slotProps.row.isListed == 2" class="color-green"
>上架</span
>
<span v-else-if="slotProps.row.isListed == 3" class="color-red"
>下架</span
>
<span v-else-if="slotProps.row.isListed == 4" class="color-orange"
>审核中</span
>
</template> </template>
<!-- 自定义-操作 --> <!-- 自定义-操作 -->
<template #action="slotProps"> <template #action="slotProps">
<el-tooltip effect="dark" placement="bottom-end"> <el-button
<template #content> text
<div class="custom-tooltip-content"> class="el-button-custom"
<el-icon class="el-icon-custom" @click="seeDetails(slotProps.row)"> @click="seeDetails(slotProps.row)"
<View /> >详情</el-button
</el-icon> >
<el-icon class="el-icon-custom" @click="toUpload(slotProps.row)"> <el-button
<Upload /> text
</el-icon> v-if="slotProps.row.isListed == 0"
<el-icon class="el-icon-custom" @click="toDownload(slotProps.row)"> class="el-button-custom"
<Download /> @click="toUpload(slotProps.row)"
</el-icon> >上架</el-button
<el-icon class="el-icon-custom" @click="handleEdit(slotProps.row)"> >
<Edit /> <el-button
</el-icon> text
<el-icon class="el-icon-custom" @click="handleDelete(slotProps.row)"> v-if="slotProps.row.isListed == 1"
<Delete /> class="el-button-custom"
</el-icon> @click="toDownload(slotProps.row)"
</div> >下架</el-button
</template> >
<el-button
<span class="el-dropdown-link"> text
<el-icon> class="el-button-custom"
<More /> @click="handleEdit(slotProps.row)"
</el-icon> >编辑</el-button
</span> >
</el-tooltip> <el-button
text
class="el-button-delete"
@click="handleDelete(slotProps.row)"
>删除</el-button
>
</template> </template>
</tableComponent> </tableComponent>
</div> </div>
@ -105,15 +173,22 @@
import { ref, reactive, computed, onMounted, onBeforeUnmount } from "vue"; import { ref, reactive, computed, onMounted, onBeforeUnmount } from "vue";
import tableComponent from "@/components/tableComponent.vue"; import tableComponent from "@/components/tableComponent.vue";
import Mock from "mockjs"; import Mock from "mockjs";
import { getGoodManageInfo, getGoodType, goodDelete } from "@/api/goods/info"; import {
getGoodManageInfo,
getGoodType,
goodDelete,
getGoodManageCount,
goodUpAndDown,
} from "@/api/goods/info";
import { id } from "element-plus/es/locales.mjs"; import { id } from "element-plus/es/locales.mjs";
import { ElMessage } from 'element-plus' import { ElMessage } from "element-plus";
const route = useRoute() const route = useRoute();
const router = useRouter() const router = useRouter();
const { proxy } = getCurrentInstance();
const formInline = reactive({ const formInline = reactive({
goodName: "", goodName: "",
goodCategoryId: "", goodCategoryId: [],
storeId: "", storeId: "",
type: "1", type: "1",
current: 1, current: 1,
@ -143,9 +218,9 @@ const resetForm = () => {
let activeCurrent = ref("1"); let activeCurrent = ref("1");
let bottomList = reactive([ let bottomList = reactive([
{ title: "全部", id: "1", value: 134 }, { title: "全部", id: "1", value: "" },
{ title: "已上架", id: "2", value: 97 }, { title: "已上架", id: "2", value: "" },
{ title: "已下架", id: "3", value: 37 }, { title: "已下架", id: "3", value: "" },
]); ]);
const tabChange = (Event) => { const tabChange = (Event) => {
console.log(Event.index); console.log(Event.index);
@ -183,7 +258,13 @@ const columns1 = ref([
{ prop: "pageView", label: "浏览量" }, { prop: "pageView", label: "浏览量" },
{ prop: "stock", label: "库存" }, { prop: "stock", label: "库存" },
{ prop: "isListed", label: "状态", slotName: "isListed" }, { prop: "isListed", label: "状态", slotName: "isListed" },
{ prop: "action", label: "操作", slotName: "action" }, {
prop: "action",
label: "操作",
slotName: "action",
width: 200,
fixed: "right",
},
]); ]);
// //
@ -224,7 +305,7 @@ const generateMockData = () => {
salesVolume: "@integer(1000, 20000)", // salesVolume: "@integer(1000, 20000)", //
pageView: Mock.mock("@id").toString().slice(0, 6), // pageView: Mock.mock("@id").toString().slice(0, 6), //
stock: "@integer(5000, 90000)", // stock: "@integer(5000, 90000)", //
isListed: '@pick([0, 1, 2, 3, 4])', // isListed: "@pick([0, 1, 2, 3, 4])", //
ordersNums: "@integer(10, 200)", ordersNums: "@integer(10, 200)",
}, },
], ],
@ -238,8 +319,12 @@ const loadData = async () => {
// tableTotal.value = tableData.value.length; // tableTotal.value = tableData.value.length;
// console.log(tableData.value); // console.log(tableData.value);
let prams = { ...formInline };
prams.goodCategoryId =
formInline.goodCategoryId[prams.goodCategoryId.length - 1];
try { try {
let response = await getGoodManageInfo(formInline); let response = await getGoodManageInfo(prams);
console.log(response); console.log(response);
if (response.code == 200) { if (response.code == 200) {
tableData.value = response.data.records; tableData.value = response.data.records;
@ -274,11 +359,24 @@ const seeDetails = (row) => {
nowClickRow.value = row; nowClickRow.value = row;
console.log("要查看详情的行:", row); console.log("要查看详情的行:", row);
}; };
const toUpload = () => { const toUpload = async (row) => {
console.log("上架:"); console.log("上架:", row);
goodsUpAndDown(row.goodId, 2);
}; };
const toDownload = () => { const toDownload = (row) => {
console.log("下架:"); console.log("下架:", row);
goodsUpAndDown(row.goodId, 3);
};
const goodsUpAndDown = async (id, isListed) => {
// 2->3->
let res = await goodUpAndDown({ id: id, isListed: isListed });
let text = isListed == 2 ? "上架" : "下架";
if (res.code == 200) {
ElMessage.success(`${text}成功`);
loadData();
} else {
ElMessage.error(res.msg);
}
}; };
// //
const handleEdit = (row) => { const handleEdit = (row) => {
@ -287,25 +385,66 @@ const handleEdit = (row) => {
// queryedit // queryedit
router.push({ router.push({
path: "/goods/goodsManage/editGoods", path: "/goods/goodsManage/editGoods",
query: { goodId: row.goodId } query: { goodId: row.goodId },
}) });
}; };
// //
const handleDelete = (row) => { const handleDelete = async (row) => {
nowClickRow.value = row; deleteGoods(row.goodId)
console.log("要删除的行:", row);
}; };
// //
const batchDelete = async () => { const batchDelete = async () => {
console.log("要删除的行:", selectedIds.value.join(",")); console.log("要删除的行:", selectedIds.value);
deleteGoods(selectedIds.value.join(","))
};
const deleteGoods = async (param) => {
try {
tableLoading.value = true;
let res = await goodDelete(param);
tableLoading.value = false;
if (res.code == 200) {
ElMessage.success("删除成功"); ElMessage.success("删除成功");
// let res = await goodDelete({id: selectedIds.value}); loadData();
// if (res.code == 200) { } else {
// ElMessage.success(""); ElMessage.error(res.msg);
// loadData(); }
// } else { } catch (error) {
// ElMessage.error(""); tableLoading.value = false;
// } }
};
//
const cascaderProps = ref({
label: "name", //
value: "id", //
children: "children", //
emitPath: true,
expandTrigger: "hover",
});
const goodsOptions = ref([]);
const getGoodTypeList = async () => {
try {
let response = await getGoodType();
console.log(response);
if (response.code == 200) {
goodsOptions.value = response.data;
}
} catch (error) {
console.log(error);
}
};
const getGoodsManageCount = async () => {
try {
let response = await getGoodManageCount();
if (response.code == 200) {
bottomList[0].value = `(${response.data?.allGoodCount ?? ""})`;
bottomList[1].value = `(${response.data?.alreadyListedCount ?? ""})`;
bottomList[2].value = `(${response.data?.removedCount ?? ""})`;
}
} catch (error) {
console.log(error);
}
}; };
const titleRef = ref(null); const titleRef = ref(null);
@ -332,6 +471,8 @@ const calculateTableHeight = () => {
onMounted(() => { onMounted(() => {
columns.value = columns1.value; columns.value = columns1.value;
loadData(); loadData();
getGoodTypeList();
getGoodsManageCount();
calculateTableHeight(); calculateTableHeight();

View File

@ -100,10 +100,10 @@ const userStore = useUserStore();
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
const { proxy } = getCurrentInstance(); const { proxy } = getCurrentInstance();
const showType = ref(1); const showType = ref(2);
const loginForm = ref({ const loginForm = ref({
username: "admin", username: "super",
password: "admin123", password: "admin123",
rememberMe: false, rememberMe: false,
code: "", code: "",

View File

@ -1,78 +1,90 @@
import { defineConfig, loadEnv } from 'vite' import { defineConfig, loadEnv } from "vite";
import path from 'path' import path from "path";
import createVitePlugins from './vite/plugins' import createVitePlugins from "./vite/plugins";
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => { export default defineConfig(({ mode, command }) => {
const env = loadEnv(mode, process.cwd()) const env = loadEnv(mode, process.cwd());
const { VITE_APP_ENV } = env const { VITE_APP_ENV } = env;
const { VITE_APP_BASE_API } = env const { VITE_APP_BASE_API } = env;
return { return {
// 部署生产环境和开发环境下的URL。 // 部署生产环境和开发环境下的URL。
// 默认情况下vite 会假设你的应用是被部署在一个域名的根路径上 // 默认情况下vite 会假设你的应用是被部署在一个域名的根路径上
// 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。 // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
base: VITE_APP_ENV === 'production' ? '/' : '/', base: VITE_APP_ENV === "production" ? "/" : "/",
plugins: createVitePlugins(env, command === 'build'), plugins: createVitePlugins(env, command === "build"),
resolve: { resolve: {
// https://cn.vitejs.dev/config/#resolve-alias // https://cn.vitejs.dev/config/#resolve-alias
alias: { alias: {
// 设置路径 // 设置路径
'~': path.resolve(__dirname, './'), "~": path.resolve(__dirname, "./"),
// 设置别名 // 设置别名
'@': path.resolve(__dirname, './src') "@": path.resolve(__dirname, "./src"),
}, },
// https://cn.vitejs.dev/config/#resolve-extensions // https://cn.vitejs.dev/config/#resolve-extensions
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'] extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
}, },
// 打包配置 // 打包配置
build: { build: {
// https://vite.dev/config/build-options.html // https://vite.dev/config/build-options.html
sourcemap: command === 'build' ? false : 'inline', sourcemap: command === "build" ? false : "inline",
outDir: 'dist', outDir: "dist",
assetsDir: 'assets', assetsDir: "assets",
chunkSizeWarningLimit: 2000, chunkSizeWarningLimit: 2000,
rollupOptions: { rollupOptions: {
output: { output: {
chunkFileNames: 'static/js/[name]-[hash].js', chunkFileNames: "static/js/[name]-[hash].js",
entryFileNames: 'static/js/[name]-[hash].js', entryFileNames: "static/js/[name]-[hash].js",
assetFileNames: 'static/[ext]/[name]-[hash].[ext]' assetFileNames: "static/[ext]/[name]-[hash].[ext]",
} },
} },
}, },
// vite 相关配置 // vite 相关配置
server: { server: {
port: 80, port: 80,
host: true, host: '0.0.0.0',
open: true, open: true,
headers: {
"Access-Control-Allow-Origin": "*",
},
proxy: { proxy: {
// https://cn.vitejs.dev/config/#server-proxy
'/apis': { '/apis': {
target: VITE_APP_BASE_API, target: VITE_APP_BASE_API,
changeOrigin: true, changeOrigin: true,
rewrite: (p) => p.replace(/^\/apis/, '') rewrite: (path) => path.replace(/^\/apis/, ""),
}, },
// springdoc proxy "^/v3/api-docs/(.*)": {
'^/v3/api-docs/(.*)': {
target: VITE_APP_BASE_API, target: VITE_APP_BASE_API,
changeOrigin: true, changeOrigin: true,
} },
} },
// proxy: {
// '/apis': {
// target: VITE_APP_BASE_API,
// changeOrigin: true,
// rewrite: (p) => p.replace(/^\/apis/, '')
// },
// '^/v3/api-docs/(.*)': {
// target: VITE_APP_BASE_API,
// changeOrigin: true,
// }
// }
}, },
css: { css: {
postcss: { postcss: {
plugins: [ plugins: [
{ {
postcssPlugin: 'internal:charset-removal', postcssPlugin: "internal:charset-removal",
AtRule: { AtRule: {
charset: (atRule) => { charset: (atRule) => {
if (atRule.name === 'charset') { if (atRule.name === "charset") {
atRule.remove() atRule.remove();
} }
} },
} },
} },
] ],
} },
} },
} };
}) });