feat(商店管理): 新增商店管理功能及相关接口和组件

- 在`smart-cabinet`接口中增加`shopId`字段,以支持商店配置
- 新增`shop.ts`接口文件,提供商店的增删改查功能
- 新增`ShopConfigModal.vue`组件,用于配置商店与智能柜的关联
- 新增`shop-form-modal.vue`组件,用于商店的新增和编辑
- 新增`shop/index.vue`页面,提供商店的列表展示和管理功能
This commit is contained in:
dzq 2025-05-09 10:54:40 +08:00
parent c2a1dc915c
commit e2f588ed9a
6 changed files with 414 additions and 0 deletions

View File

@ -12,6 +12,7 @@ export interface SmartCabinetDTO {
cabinetName: string;
cabinetType: number;
mqttServerId?: number;
shopId?: number;
templateNo: string;
lockControlNo: number;
location: number;
@ -22,6 +23,7 @@ export interface AddSmartCabinetCommand {
cabinetName: string;
cabinetType: number;
mqttServerId?: number;
shopId?: number;
templateNo: string;
lockControlNo: number;
location: number;
@ -32,6 +34,7 @@ export interface UpdateSmartCabinetCommand {
cabinetName?: string;
cabinetType?: number;
mqttServerId?: number;
shopId?: number;
templateNo?: string;
lockControlNo?: number;
location?: number;

49
src/api/shop/shop.ts Normal file
View File

@ -0,0 +1,49 @@
import { http } from '@/utils/http';
/** 商店分页查询参数 */
export interface ShopQuery extends BasePageQuery {
shopName?: string;
}
/** 商店DTO */
export interface ShopDTO {
shopId: number;
shopName: string;
}
/** 新增商店命令 */
export interface AddShopCommand {
shopName: string;
}
/** 更新商店命令 */
export interface UpdateShopCommand {
shopId: number;
shopName: string;
}
/** 获取商店列表 */
export const getShopList = (params?: ShopQuery) => {
return http.request<ResponseData<PageDTO<ShopDTO>>>('get', '/shop/shops', {
params
});
};
/** 新增商店 */
export const addShop = (data: AddShopCommand) => {
return http.request<ResponseData<void>>('post', '/shop/shops', {
data
});
};
/** 修改商店 */
export const updateShop = (id: number, data: UpdateShopCommand) => {
return http.request<ResponseData<void>>('put', `/shop/shops/${id}`, {
data
});
};
/** 删除商店 */
export const deleteShop = (ids: string) => {
return http.request<ResponseData<void>>('delete', `/shop/shops/${ids}`);
};

View File

@ -0,0 +1,174 @@
<script setup lang="ts">
import { ref } from "vue";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { getShopList, ShopDTO, deleteShop, ShopQuery } from "@/api/shop/shop";
import EditPen from "@iconify-icons/ep/edit-pen";
import Delete from "@iconify-icons/ep/delete";
import AddFill from "@iconify-icons/ri/add-circle-line";
import Search from "@iconify-icons/ep/search";
import Refresh from "@iconify-icons/ep/refresh";
import { ElMessage, ElMessageBox } from "element-plus";
import ShopFormModal from "./shop-form-modal.vue";
defineOptions({
name: "Shop"
});
const formRef = ref();
const tableRef = ref();
const modalVisible = ref(false);
const handleRefresh = () => {
getList();
modalVisible.value = false;
editVisible.value = false;
};
const searchFormParams = ref<ShopQuery>({
shopName: ""
});
const pagination = ref({
pageSize: 10,
currentPage: 1,
total: 0
});
const loading = ref(false);
const dataList = ref<ShopDTO[]>([]);
const multipleSelection = ref<number[]>([]);
const editVisible = ref(false);
const currentRow = ref<ShopDTO>();
const getList = async () => {
try {
loading.value = true;
const { data } = await getShopList({
...searchFormParams.value,
pageSize: pagination.value.pageSize,
pageNum: pagination.value.currentPage
});
dataList.value = data.rows;
pagination.value.total = data.total;
} finally {
loading.value = false;
}
};
const onSearch = () => {
pagination.value.currentPage = 1;
getList();
};
const resetForm = () => {
formRef.value.resetFields();
onSearch();
};
const onSizeChange = (val: number) => {
pagination.value.pageSize = val;
getList();
};
const onCurrentChange = (val: number) => {
pagination.value.currentPage = val;
getList();
};
const handleDelete = async (row: ShopDTO) => {
try {
await deleteShop(row.shopId!.toString());
ElMessage.success("删除成功");
getList();
} catch (error) {
console.error("删除失败", error);
}
};
const handleBulkDelete = async () => {
if (multipleSelection.value.length === 0) return;
try {
await ElMessageBox.confirm(
`确认删除选中的${multipleSelection.value.length}家商店吗?`,
"警告",
{ confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }
);
await deleteShop(multipleSelection.value.join(","));
ElMessage.success("批量删除成功");
multipleSelection.value = [];
getList();
} catch (error) {
console.error("删除取消或失败", error);
}
};
const handleSelectionChange = (rows: ShopDTO[]) => {
multipleSelection.value = rows.map(row => row.shopId!);
};
const handleEdit = (row: ShopDTO) => {
currentRow.value = row;
editVisible.value = true;
};
getList();
</script>
<template>
<div class="main">
<el-form ref="formRef" :inline="true" :model="searchFormParams"
class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]">
<el-form-item label="商店名称:" prop="shopName">
<el-input v-model="searchFormParams.shopName" placeholder="请输入商店名称" clearable class="!w-[200px]" />
</el-form-item>
<el-form-item>
<el-button type="primary" :icon="useRenderIcon(Search)" @click="onSearch">
搜索
</el-button>
<el-button :icon="useRenderIcon(Refresh)" @click="resetForm">
重置
</el-button>
</el-form-item>
</el-form>
<PureTableBar title="商店管理" @refresh="getList">
<template #buttons>
<el-button type="primary" :icon="useRenderIcon(AddFill)" @click="modalVisible = true">
新增商店
</el-button>
<el-button type="danger" :icon="useRenderIcon(Delete)" :disabled="multipleSelection.length === 0"
@click="handleBulkDelete">
批量删除
</el-button>
</template>
<el-table ref="tableRef" v-loading="loading" :data="dataList" row-key="id"
@selection-change="handleSelectionChange" border>
<el-table-column type="selection" width="55" />
<el-table-column label="商店ID" prop="shopId" width="100" />
<el-table-column label="商店名称" prop="shopName" />
<el-table-column label="操作" width="150" fixed="right">
<template #default="{ row }">
<el-button type="primary" link :icon="useRenderIcon(EditPen)" @click="handleEdit(row)">
编辑
</el-button>
<el-popconfirm :title="`确认删除【${row.shopName}】?`" @confirm="handleDelete(row)">
<template #reference>
<el-button type="danger" link :icon="useRenderIcon(Delete)">
删除
</el-button>
</template>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
<el-pagination v-model:current-page="pagination.currentPage" v-model:page-size="pagination.pageSize"
:page-sizes="[10, 20, 50]" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
@size-change="onSizeChange" @current-change="onCurrentChange" />
</PureTableBar>
<ShopFormModal :visible="modalVisible" @update:visible="val => modalVisible = val" @refresh="handleRefresh" />
<ShopFormModal :visible="editVisible" :row="currentRow" @update:visible="val => editVisible = val"
@refresh="handleRefresh" />
</div>
</template>

View File

@ -0,0 +1,88 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import { ElMessage } from "element-plus";
import { addShop, updateShop, ShopDTO, UpdateShopCommand } from "@/api/shop/shop";
const props = defineProps({
visible: {
type: Boolean,
default: false
},
row: {
type: Object as () => ShopDTO,
default: () => ({})
}
});
const emit = defineEmits(["update:visible", "refresh"]);
const formRef = ref();
const formData = ref<UpdateShopCommand>({
shopId: 0,
shopName: ""
});
const rules = {
shopName: [{ required: true, message: "请输入商店名称", trigger: "blur" }]
};
watch(
() => props.visible,
val => {
if (val) {
if (props.row?.shopId) {
formData.value = {
...props.row,
shopId: props.row.shopId
};
} else {
formData.value = {
shopId: 0,
shopName: ""
};
}
}
}
);
const handleSubmit = async () => {
try {
await formRef.value.validate();
if (formData.value.shopId) {
await updateShop(formData.value.shopId, formData.value);
ElMessage.success("修改成功");
} else {
await addShop(formData.value);
ElMessage.success("新增成功");
}
emit("update:visible", false);
emit("refresh");
} catch (error) {
console.error(error);
}
};
const handleClose = () => {
emit("update:visible", false);
};
</script>
<template>
<el-dialog :title="formData.shopId ? '编辑商店' : '新增商店'" :model-value="visible" @update:model-value="handleClose"
width="600px">
<el-form ref="formRef" :model="formData" :rules="rules" label-width="100px">
<el-form-item label="商店ID" prop="shopId" v-if="formData.shopId">
<el-input v-model="formData.shopId" :disabled="true" />
</el-form-item>
<el-form-item label="商店名称" prop="shopName">
<el-input v-model="formData.shopName" placeholder="请输入商店名称" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" @click="handleSubmit">确定</el-button>
</template>
</el-dialog>
</template>

View File

@ -0,0 +1,89 @@
<template>
<el-dialog v-model="visible" title="商店配置" width="800px">
<el-table :data="shopList" v-loading="loading" border>
<el-table-column prop="shopId" label="商店ID" width="100" />
<el-table-column prop="shopName" label="商店名称" />
<el-table-column label="操作" width="80" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="handleConfig(row)">配置</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination v-model:current-page="pagination.currentPage" v-model:page-size="pagination.pageSize"
:page-sizes="[10, 20, 50]" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
@size-change="onSizeChange" @current-change="onCurrentChange" />
</el-dialog>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue';
import { getShopList } from '@/api/shop/shop';
import { ShopDTO } from '@/api/shop/shop';
import { ElMessage } from 'element-plus';
import { updateSmartCabinet } from '@/api/cabinet/smart-cabinet';
const props = defineProps<{
modelValue: boolean;
cabinetId: number;
}>();
const emit = defineEmits(['update:modelValue']);
const visible = ref(props.modelValue);
const shopList = ref<ShopDTO[]>([]);
const loading = ref(false);
const currentCabinetId = ref<number>();
const pagination = ref({
pageSize: 10,
currentPage: 1,
total: 0
});
const loadShops = async () => {
try {
loading.value = true;
const { data } = await getShopList({
pageSize: pagination.value.pageSize,
pageNum: pagination.value.currentPage
});
shopList.value = data.rows;
pagination.value.total = data.total;
} finally {
loading.value = false;
}
};
const onSizeChange = (val: number) => {
pagination.value.pageSize = val;
loadShops();
};
const onCurrentChange = (val: number) => {
pagination.value.currentPage = val;
loadShops();
};
watch(() => props.modelValue, (val) => {
visible.value = val;
});
watch(() => props.cabinetId, (newVal) => {
if (newVal) {
currentCabinetId.value = newVal;
loadShops();
}
});
const handleConfig = async (row: ShopDTO) => {
try {
await updateSmartCabinet(currentCabinetId.value, {
cabinetId: currentCabinetId.value,
shopId: row.shopId
});
ElMessage.success('配置成功');
emit('update:modelValue', false);
} catch (error) {
console.error('配置失败', error);
}
};
</script>

View File

@ -15,6 +15,7 @@ import router from "@/router";
import { deleteSmartCabinet } from "@/api/cabinet/smart-cabinet";
import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
import GatewayConfigModal from "./GatewayConfigModal.vue";
import ShopConfigModal from "./ShopConfigModal.vue";
defineOptions({
name: "SmartCabinet"
@ -41,6 +42,7 @@ const multipleSelection = ref<number[]>([]);
const editVisible = ref(false);
const currentRow = ref<SmartCabinetDTO>();
const gatewayConfigVisible = ref(false);
const shopConfigVisible = ref(false);
const currentCabinetId = ref<number>();
const getList = async () => {
@ -138,6 +140,11 @@ const handleGatewayConfig = (row: SmartCabinetDTO) => {
gatewayConfigVisible.value = true;
};
const handleShopConfig = (row: SmartCabinetDTO) => {
currentCabinetId.value = row.cabinetId;
shopConfigVisible.value = true;
};
getList();
</script>
@ -200,6 +207,9 @@ getList();
@click="handleGatewayConfig(row)">
配置网关
</el-button>
<el-button type="success" link :icon="useRenderIcon('ep:shop')" @click="handleShopConfig(row)">
配置商店
</el-button>
<el-popconfirm :title="`确认删除【${row.cabinetName}】?`" @confirm="handleDelete(row)">
<template #reference>
<el-button type="danger" link :icon="useRenderIcon(Delete)">
@ -217,5 +227,6 @@ getList();
<smart-cabinet-form-modal v-model:visible="modalVisible" @refresh="getList" />
<smart-cabinet-edit-modal v-model:visible="editVisible" :row="currentRow" @refresh="getList" />
<GatewayConfigModal v-model="gatewayConfigVisible" :cabinet-id="currentCabinetId" />
<ShopConfigModal v-model="shopConfigVisible" :cabinet-id="currentCabinetId" />
</div>
</template>