补充完善mybatis的前端演示代码
This commit is contained in:
parent
64434a466e
commit
cc4d3a8ebd
63
src/api/demo/customer/index.ts
Normal file
63
src/api/demo/customer/index.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import request from '@/utils/request';
|
||||
import { AxiosPromise } from 'axios';
|
||||
import { DemoCustomerVO, DemoCustomerForm, DemoCustomerQuery } from '@/api/demo/customer/types';
|
||||
|
||||
/**
|
||||
* 查询客户主表列表
|
||||
* @param query
|
||||
* @returns {*}
|
||||
*/
|
||||
|
||||
export const listCustomer = (query?: DemoCustomerQuery): AxiosPromise<DemoCustomerVO[]> => {
|
||||
return request({
|
||||
url: '/demo/customer/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询客户主表详细
|
||||
* @param customerId
|
||||
*/
|
||||
export const getCustomer = (customerId: string | number): AxiosPromise<DemoCustomerVO> => {
|
||||
return request({
|
||||
url: '/demo/customer/' + customerId,
|
||||
method: 'get'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 新增客户主表
|
||||
* @param data
|
||||
*/
|
||||
export const addCustomer = (data: DemoCustomerForm) => {
|
||||
return request({
|
||||
url: '/demo/customer',
|
||||
method: 'post',
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改客户主表
|
||||
* @param data
|
||||
*/
|
||||
export const updateCustomer = (data: DemoCustomerForm) => {
|
||||
return request({
|
||||
url: '/demo/customer',
|
||||
method: 'put',
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除客户主表
|
||||
* @param customerId
|
||||
*/
|
||||
export const delCustomer = (customerId: string | number | Array<string | number>) => {
|
||||
return request({
|
||||
url: '/demo/customer/' + customerId,
|
||||
method: 'delete'
|
||||
});
|
||||
};
|
119
src/api/demo/customer/types.ts
Normal file
119
src/api/demo/customer/types.ts
Normal file
@ -0,0 +1,119 @@
|
||||
export interface DemoCustomerVO extends BaseEntity {
|
||||
/**
|
||||
* 客户姓名
|
||||
*/
|
||||
customerName: string;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
phonenumber: string;
|
||||
|
||||
/**
|
||||
* 客户性别
|
||||
*/
|
||||
gender: string;
|
||||
|
||||
/**
|
||||
* 客户生日
|
||||
*/
|
||||
birthday: string;
|
||||
|
||||
/** 商品子表信息 */
|
||||
goodsList: Array<DemoGoodsVO>;
|
||||
}
|
||||
|
||||
export interface DemoGoodsVO extends BaseEntity {
|
||||
/** 列表序号 */
|
||||
index:number;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* 商品重量
|
||||
*/
|
||||
weight: number;
|
||||
|
||||
/**
|
||||
* 商品价格
|
||||
*/
|
||||
price: number;
|
||||
|
||||
/**
|
||||
* 商品时间
|
||||
*/
|
||||
date: string;
|
||||
|
||||
/**
|
||||
* 商品种类
|
||||
*/
|
||||
type: string;
|
||||
|
||||
/**
|
||||
* 乐观锁
|
||||
*/
|
||||
version: number;
|
||||
|
||||
}
|
||||
|
||||
export interface DemoCustomerForm {
|
||||
/**
|
||||
* 客户id
|
||||
*/
|
||||
customerId?: string | number;
|
||||
|
||||
/**
|
||||
* 客户姓名
|
||||
*/
|
||||
customerName?: string;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
phonenumber?: string;
|
||||
|
||||
/**
|
||||
* 客户性别
|
||||
*/
|
||||
gender?: string;
|
||||
|
||||
/**
|
||||
* 客户生日
|
||||
*/
|
||||
birthday?: string;
|
||||
|
||||
/**
|
||||
* 客户描述
|
||||
*/
|
||||
remark?: string;
|
||||
|
||||
/**
|
||||
* 乐观锁
|
||||
*/
|
||||
version?: number;
|
||||
|
||||
}
|
||||
|
||||
export interface DemoCustomerQuery extends PageQuery {
|
||||
/**
|
||||
* 客户姓名
|
||||
*/
|
||||
customerName?: string;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
phonenumber?: string;
|
||||
|
||||
/**
|
||||
* 客户性别
|
||||
*/
|
||||
gender?: string;
|
||||
|
||||
/**
|
||||
* 日期范围参数
|
||||
*/
|
||||
params?: any;
|
||||
}
|
63
src/api/demo/product/index.ts
Normal file
63
src/api/demo/product/index.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import request from '@/utils/request';
|
||||
import { AxiosPromise } from 'axios';
|
||||
import { DemoProductVO, DemoProductForm, DemoProductQuery } from '@/api/demo/product/types';
|
||||
|
||||
/**
|
||||
* 查询产品树列表
|
||||
* @param query
|
||||
* @returns {*}
|
||||
*/
|
||||
|
||||
export const listProduct = (query?: DemoProductQuery): AxiosPromise<DemoProductVO[]> => {
|
||||
return request({
|
||||
url: '/demo/product/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询产品树详细
|
||||
* @param productId
|
||||
*/
|
||||
export const getProduct = (productId: string | number): AxiosPromise<DemoProductVO> => {
|
||||
return request({
|
||||
url: '/demo/product/' + productId,
|
||||
method: 'get'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 新增产品树
|
||||
* @param data
|
||||
*/
|
||||
export const addProduct = (data: DemoProductForm) => {
|
||||
return request({
|
||||
url: '/demo/product',
|
||||
method: 'post',
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改产品树
|
||||
* @param data
|
||||
*/
|
||||
export const updateProduct = (data: DemoProductForm) => {
|
||||
return request({
|
||||
url: '/demo/product',
|
||||
method: 'put',
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除产品树
|
||||
* @param productId
|
||||
*/
|
||||
export const delProduct = (productId: string | number | Array<string | number>) => {
|
||||
return request({
|
||||
url: '/demo/product/' + productId,
|
||||
method: 'delete'
|
||||
});
|
||||
};
|
78
src/api/demo/product/types.ts
Normal file
78
src/api/demo/product/types.ts
Normal file
@ -0,0 +1,78 @@
|
||||
import { DemoStudentVO } from '@/api/demo/student/types';
|
||||
|
||||
export interface DemoProductVO extends BaseEntity {
|
||||
/**
|
||||
* 父产品id
|
||||
*/
|
||||
parentId: string | number;
|
||||
|
||||
/**
|
||||
* 产品名称
|
||||
*/
|
||||
productName: string;
|
||||
|
||||
/**
|
||||
* 显示顺序
|
||||
*/
|
||||
orderNum: number;
|
||||
|
||||
/**
|
||||
* 产品状态(0正常 1停用)
|
||||
*/
|
||||
status: string;
|
||||
|
||||
/**
|
||||
* 子对象
|
||||
*/
|
||||
children: DemoProductVO[];
|
||||
}
|
||||
|
||||
export interface DemoProductForm {
|
||||
/**
|
||||
* 产品id
|
||||
*/
|
||||
productId?: string | number;
|
||||
|
||||
/**
|
||||
* 父产品id
|
||||
*/
|
||||
parentId?: string | number;
|
||||
|
||||
/**
|
||||
* 产品名称
|
||||
*/
|
||||
productName?: string;
|
||||
|
||||
/**
|
||||
* 显示顺序
|
||||
*/
|
||||
orderNum?: number;
|
||||
|
||||
/**
|
||||
* 产品状态(0正常 1停用)
|
||||
*/
|
||||
status?: string;
|
||||
|
||||
/**
|
||||
* 乐观锁
|
||||
*/
|
||||
version?: number;
|
||||
|
||||
}
|
||||
|
||||
export interface DemoProductQuery {
|
||||
/**
|
||||
* 产品名称
|
||||
*/
|
||||
productName?: string;
|
||||
|
||||
/**
|
||||
* 产品状态(0正常 1停用)
|
||||
*/
|
||||
status?: string;
|
||||
|
||||
/**
|
||||
* 日期范围参数
|
||||
*/
|
||||
params?: any;
|
||||
}
|
63
src/api/demo/student/index.ts
Normal file
63
src/api/demo/student/index.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import request from '@/utils/request';
|
||||
import { AxiosPromise } from 'axios';
|
||||
import { DemoStudentVO, DemoStudentForm, DemoStudentQuery } from '@/api/demo/student/types';
|
||||
|
||||
/**
|
||||
* 查询学生信息表列表
|
||||
* @param query
|
||||
* @returns {*}
|
||||
*/
|
||||
|
||||
export const listStudent = (query?: DemoStudentQuery): AxiosPromise<DemoStudentVO[]> => {
|
||||
return request({
|
||||
url: '/demo/student/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询学生信息表详细
|
||||
* @param studentId
|
||||
*/
|
||||
export const getStudent = (studentId: string | number): AxiosPromise<DemoStudentVO> => {
|
||||
return request({
|
||||
url: '/demo/student/' + studentId,
|
||||
method: 'get'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 新增学生信息表
|
||||
* @param data
|
||||
*/
|
||||
export const addStudent = (data: DemoStudentForm) => {
|
||||
return request({
|
||||
url: '/demo/student',
|
||||
method: 'post',
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改学生信息表
|
||||
* @param data
|
||||
*/
|
||||
export const updateStudent = (data: DemoStudentForm) => {
|
||||
return request({
|
||||
url: '/demo/student',
|
||||
method: 'put',
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除学生信息表
|
||||
* @param studentId
|
||||
*/
|
||||
export const delStudent = (studentId: string | number | Array<string | number>) => {
|
||||
return request({
|
||||
url: '/demo/student/' + studentId,
|
||||
method: 'delete'
|
||||
});
|
||||
};
|
96
src/api/demo/student/types.ts
Normal file
96
src/api/demo/student/types.ts
Normal file
@ -0,0 +1,96 @@
|
||||
export interface DemoStudentVO extends BaseEntity {
|
||||
/**
|
||||
* 学生名称
|
||||
*/
|
||||
studentName: string;
|
||||
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
studentAge: number;
|
||||
|
||||
/**
|
||||
* 爱好(0代码 1音乐 2电影)
|
||||
*/
|
||||
studentHobby: string;
|
||||
|
||||
/**
|
||||
* 性别(1男 2女 3未知)
|
||||
*/
|
||||
studentGender: string;
|
||||
|
||||
/**
|
||||
* 状态(0正常 1停用)
|
||||
*/
|
||||
studentStatus: string;
|
||||
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
studentBirthday: string;
|
||||
|
||||
}
|
||||
|
||||
export interface DemoStudentForm {
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
studentId?: string | number;
|
||||
|
||||
/**
|
||||
* 学生名称
|
||||
*/
|
||||
studentName?: string;
|
||||
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
studentAge?: number;
|
||||
|
||||
/**
|
||||
* 爱好(0代码 1音乐 2电影)
|
||||
*/
|
||||
studentHobby?: string;
|
||||
|
||||
/**
|
||||
* 性别(1男 2女 3未知)
|
||||
*/
|
||||
studentGender?: string;
|
||||
|
||||
/**
|
||||
* 状态(0正常 1停用)
|
||||
*/
|
||||
studentStatus?: string;
|
||||
|
||||
/**
|
||||
* 生日
|
||||
*/
|
||||
studentBirthday?: string;
|
||||
|
||||
/**
|
||||
* 乐观锁
|
||||
*/
|
||||
version?: number;
|
||||
|
||||
}
|
||||
|
||||
export interface DemoStudentQuery extends PageQuery {
|
||||
|
||||
/**
|
||||
* 学生名称
|
||||
*/
|
||||
studentName?: string;
|
||||
|
||||
/**
|
||||
* 状态(0正常 1停用)
|
||||
*/
|
||||
studentStatus?: string;
|
||||
|
||||
/**
|
||||
* 日期范围参数
|
||||
*/
|
||||
params?: any;
|
||||
}
|
||||
|
||||
|
||||
|
394
src/views/demo/customer/index.vue
Normal file
394
src/views/demo/customer/index.vue
Normal file
@ -0,0 +1,394 @@
|
||||
<template>
|
||||
<div class="p-2">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||
<div class="search" v-show="showSearch">
|
||||
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
|
||||
<el-form-item label="客户姓名" prop="customerName">
|
||||
<el-input v-model="queryParams.customerName" placeholder="请输入客户姓名" clearable style="width: 240px" @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号码" prop="phonenumber">
|
||||
<el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable style="width: 240px" @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item label="客户性别" prop="sex">
|
||||
<el-select v-model="queryParams.sex" placeholder="请选择客户性别" clearable style="width: 240px">
|
||||
<el-option
|
||||
v-for="dict in sys_user_gender"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="客户生日" prop="birthday">
|
||||
<el-date-picker clearable
|
||||
v-model="queryParams.birthday"
|
||||
type="date"
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
placeholder="请选择客户生日">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['demo:customer:add']">新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['demo:customer:edit']">修改</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['demo:customer:remove']">删除</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['demo:customer:export']">导出</el-button>
|
||||
</el-col>
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<el-table v-loading="loading" :data="customerList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="客户id" align="center" prop="customerId" v-if="false" />
|
||||
<el-table-column label="客户姓名" align="center" prop="customerName" />
|
||||
<el-table-column label="手机号码" align="center" prop="phonenumber" />
|
||||
<el-table-column label="客户性别" align="center" prop="sex">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="sys_user_gender" :value="scope.row.sex"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="客户生日" align="center" prop="birthday" width="180">
|
||||
<template #default="scope">
|
||||
<span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-tooltip content="修改" placement="top">
|
||||
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['demo:customer:edit']"></el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip content="删除" placement="top">
|
||||
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['demo:customer:remove']"></el-button>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNum"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</el-card>
|
||||
<!-- 添加或修改客户主表对话框 -->
|
||||
<el-dialog :title="dialog.title" v-model="dialog.visible" width="780px" append-to-body>
|
||||
<el-form ref="customerFormRef" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="客户姓名" prop="customerName">
|
||||
<el-input v-model="form.customerName" placeholder="请输入客户姓名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号码" prop="phonenumber">
|
||||
<el-input v-model="form.phonenumber" placeholder="请输入手机号码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="客户性别" prop="sex">
|
||||
<el-select v-model="form.sex" placeholder="请选择客户性别">
|
||||
<el-option
|
||||
v-for="dict in sys_user_gender"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="客户生日" prop="birthday">
|
||||
<el-date-picker clearable
|
||||
v-model="form.birthday"
|
||||
type="date"
|
||||
value-format="YYYY-MM-DD"
|
||||
placeholder="请选择客户生日">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item label="客户描述" prop="remark">
|
||||
<el-input v-model="form.remark" placeholder="请输入客户描述" />
|
||||
</el-form-item>
|
||||
<el-form-item label="乐观锁" prop="version" v-show="false">
|
||||
<el-input v-model="form.version" placeholder="请输入乐观锁" />
|
||||
</el-form-item>
|
||||
<el-divider content-position="center">商品子表信息</el-divider>
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" icon="Plus" @click="handleAddGoods">添加</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="danger" icon="Delete" @click="handleDeleteGoods">删除</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-table :data="goodsList" :row-class-name="rowGoodsIndex" @selection-change="handleGoodsSelectionChange" ref="goods">
|
||||
<el-table-column type="selection" width="50" align="center" />
|
||||
<el-table-column label="序号" align="center" prop="index" width="50" />
|
||||
<el-table-column label="商品名称" prop="name" width="150">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.name" placeholder="请输入商品名称" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品重量" prop="weight" width="150">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.weight" placeholder="请输入商品重量" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品价格" prop="price" width="150">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.price" placeholder="请输入商品价格" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品时间" prop="date" width="240">
|
||||
<template #default="scope">
|
||||
<el-date-picker clearable
|
||||
v-model="scope.row.date"
|
||||
type="date"
|
||||
value-format="YYYY-MM-DD"
|
||||
placeholder="请选择商品时间">
|
||||
</el-date-picker>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品种类" prop="type" width="150">
|
||||
<template #default="scope">
|
||||
<el-select v-model="scope.row.type" placeholder="请选择商品种类">
|
||||
<el-option
|
||||
v-for="dict in sys_goods_type"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column v-if="false" label="乐观锁" prop="version" width="150">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.version" placeholder="请输入乐观锁" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="Customer" lang="ts">
|
||||
import { listCustomer, getCustomer, delCustomer, addCustomer, updateCustomer } from '@/api/demo/customer';
|
||||
import { DemoCustomerVO, DemoCustomerQuery, DemoCustomerForm, DemoGoodsVO } from '@/api/demo/customer/types';
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const { sys_goods_type, sys_user_gender } = toRefs<any>(proxy?.useDict('sys_goods_type', 'sys_user_gender'));
|
||||
|
||||
// 表格数据
|
||||
const customerList = ref<DemoCustomerVO[]>([]);
|
||||
// 子表格数据
|
||||
const goodsList = ref<DemoGoodsVO[]>([]);
|
||||
const buttonLoading = ref(false);
|
||||
const loading = ref(true);
|
||||
const showSearch = ref(true);
|
||||
// 选中数组
|
||||
const ids = ref<Array<string | number>>([]);
|
||||
// 子表选中数据
|
||||
const checkedGoods = ref<DemoGoodsVO[]>([]);
|
||||
// 非单个禁用
|
||||
const single = ref(true);
|
||||
// 非多个禁用
|
||||
const multiple = ref(true);
|
||||
// 总条数
|
||||
const total = ref(0);
|
||||
|
||||
const queryFormRef = ref<ElFormInstance>();
|
||||
const customerFormRef = ref<ElFormInstance>();
|
||||
|
||||
const dialog = reactive<DialogOption>({
|
||||
visible: false,
|
||||
title: ''
|
||||
});
|
||||
|
||||
const initFormData: DemoCustomerForm = {
|
||||
customerId: undefined,
|
||||
customerName: undefined,
|
||||
phonenumber: undefined,
|
||||
gender: undefined,
|
||||
birthday: undefined,
|
||||
remark: undefined,
|
||||
version: 0,
|
||||
};
|
||||
const data = reactive<PageData<DemoCustomerForm, DemoCustomerQuery>>({
|
||||
form: {...initFormData},
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
customerName: undefined,
|
||||
phonenumber: undefined,
|
||||
sex: undefined,
|
||||
params: {
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
customerName: [
|
||||
{ required: true, message: "客户姓名不能为空", trigger: "blur" }
|
||||
],
|
||||
phonenumber: [
|
||||
{ required: true, message: "手机号码不能为空", trigger: "blur" }
|
||||
],
|
||||
sex: [
|
||||
{ required: true, message: "客户性别不能为空", trigger: "change" }
|
||||
],
|
||||
birthday: [
|
||||
{ required: true, message: "客户生日不能为空", trigger: "blur" }
|
||||
],
|
||||
}
|
||||
});
|
||||
|
||||
const { queryParams, form, rules } = toRefs(data);
|
||||
|
||||
/** 查询客户主表列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true;
|
||||
const res = await listCustomer(queryParams.value);
|
||||
customerList.value = res.rows;
|
||||
total.value = res.total;
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
/** 取消按钮 */
|
||||
const cancel = () => {
|
||||
reset();
|
||||
dialog.visible = false;
|
||||
};
|
||||
|
||||
/** 表单重置 */
|
||||
const reset = () => {
|
||||
form.value = {...initFormData};
|
||||
goodsList.value = [];
|
||||
customerFormRef.value?.resetFields();
|
||||
};
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.value.pageNum = 1;
|
||||
getList();
|
||||
};
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value?.resetFields();
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/** 多选框选中数据 */
|
||||
const handleSelectionChange = (selection: DemoCustomerVO[]) => {
|
||||
ids.value = selection.map(item => item.customerId);
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
};
|
||||
|
||||
/** 新增按钮操作 */
|
||||
const handleAdd = () => {
|
||||
reset();
|
||||
dialog.visible = true;
|
||||
dialog.title = '添加客户主表';
|
||||
};
|
||||
|
||||
/** 修改按钮操作 */
|
||||
const handleUpdate = async (row?: DemoCustomerVO) => {
|
||||
reset();
|
||||
const _customerId = row?.customerId || ids.value[0];
|
||||
const res = await getCustomer(_customerId);
|
||||
Object.assign(form.value, res.data);
|
||||
goodsList.value = res.data.demoGoodsList;
|
||||
dialog.visible = true;
|
||||
dialog.title = '修改客户主表';
|
||||
};
|
||||
|
||||
/** 提交按钮 */
|
||||
const submitForm = () => {
|
||||
customerFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
buttonLoading.value = true;
|
||||
form.value.goodsList = goodsList.value;
|
||||
if (form.value.customerId) {
|
||||
await updateCustomer(form.value).finally(() => (buttonLoading.value = false));
|
||||
} else {
|
||||
await addCustomer(form.value).finally(() => (buttonLoading.value = false));
|
||||
}
|
||||
proxy?.$modal.msgSuccess('修改成功');
|
||||
dialog.visible = false;
|
||||
await getList();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (row?: DemoCustomerVO) => {
|
||||
const _customerIds = row?.customerId || ids.value;
|
||||
await proxy?.$modal.confirm('是否确认删除客户主表编号为"' + _customerIds + '"的数据项?').finally(() => loading.value = false);
|
||||
await delCustomer(_customerIds);
|
||||
proxy?.$modal.msgSuccess("删除成功");
|
||||
await getList();
|
||||
};
|
||||
|
||||
/** 商品子表序号 */
|
||||
const rowGoodsIndex = ({row,rowIndex}: {row: DemoGoodsVO,rowIndex: number}) => {
|
||||
row.index = rowIndex + 1;
|
||||
}
|
||||
|
||||
/** 商品子表添加按钮操作 */
|
||||
const handleAddGoods = () => {
|
||||
let obj = {};
|
||||
obj.name = "";
|
||||
obj.weight = "";
|
||||
obj.price = "";
|
||||
obj.date = "";
|
||||
obj.type = "";
|
||||
obj.version = 0;
|
||||
goodsList.value.push(obj);
|
||||
}
|
||||
|
||||
/** 商品子表删除按钮操作 */
|
||||
const handleDeleteGoods = () => {
|
||||
if (checkedGoods.value.length == 0) {
|
||||
proxy.$modal.msgError("请先选择要删除的商品子表数据");
|
||||
} else {
|
||||
const goodss = goodsList.value;
|
||||
const checkedGoodss = checkedGoods.value;
|
||||
goodsList.value = goodss.filter(function(item) {
|
||||
return checkedGoodss.indexOf(item.index) == -1
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** 复选框选中数据 */
|
||||
const handleGoodsSelectionChange = (selection: DemoGoodsVO[]) => {
|
||||
checkedGoods.value = selection.map(item => item.index)
|
||||
}
|
||||
|
||||
/** 导出按钮操作 */
|
||||
const handleExport = () => {
|
||||
proxy?.download('demo/customer/export', {
|
||||
...queryParams.value
|
||||
}, `customer_${new Date().getTime()}.xlsx`)
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
289
src/views/demo/product/index.vue
Normal file
289
src/views/demo/product/index.vue
Normal file
@ -0,0 +1,289 @@
|
||||
<template>
|
||||
<div class="p-2">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||
<div class="search" v-show="showSearch">
|
||||
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
|
||||
<el-form-item label="产品名称" prop="productName">
|
||||
<el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable style="width: 240px" @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item label="产品状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="请选择产品状态" clearable style="width: 240px">
|
||||
<el-option
|
||||
v-for="dict in sys_common_status"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="Plus" @click="handleAdd()" v-hasPermi="['demo:product:add']">新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="info" plain icon="Sort" @click="handleToggleExpandAll">展开/折叠</el-button>
|
||||
</el-col>
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
</template>
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="productList"
|
||||
row-key="productId"
|
||||
:default-expand-all="isExpandAll"
|
||||
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
||||
ref="productTableRef"
|
||||
>
|
||||
<el-table-column label="产品名称" align="center" prop="productName" />
|
||||
<el-table-column label="显示顺序" align="center" prop="orderNum" />
|
||||
<el-table-column label="产品状态" align="center" prop="status">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="sys_common_status" :value="scope.row.status"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-tooltip content="修改" placement="top">
|
||||
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['demo:product:edit']" />
|
||||
</el-tooltip>
|
||||
<el-tooltip content="新增" placement="top">
|
||||
<el-button link type="primary" icon="Plus" @click="handleAdd(scope.row)" v-hasPermi="['demo:product:add']" />
|
||||
</el-tooltip>
|
||||
<el-tooltip content="删除" placement="top">
|
||||
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['demo:product:remove']" />
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
<!-- 添加或修改产品树对话框 -->
|
||||
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||
<el-form ref="productFormRef" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="父产品id" prop="parentId">
|
||||
<el-tree-select
|
||||
v-model="form.parentId"
|
||||
:data="productOptions"
|
||||
:props="{ value: 'productId', label: 'productName', children: 'children' }"
|
||||
value-key="productId"
|
||||
placeholder="请选择父产品id"
|
||||
check-strictly
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="产品名称" prop="productName">
|
||||
<el-input v-model="form.productName" placeholder="请输入产品名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="显示顺序" prop="orderNum">
|
||||
<el-input v-model="form.orderNum" placeholder="请输入显示顺序" />
|
||||
</el-form-item>
|
||||
<el-form-item label="产品状态" prop="status">
|
||||
<el-radio-group v-model="form.status">
|
||||
<el-radio
|
||||
v-for="dict in sys_common_status"
|
||||
:key="dict.value"
|
||||
:label="dict.value"
|
||||
>{{dict.label}}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="乐观锁" prop="version" v-show="false">
|
||||
<el-input v-model="form.version" placeholder="请输入乐观锁" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="DemoProduct" lang="ts">
|
||||
import { listProduct, getProduct, delProduct, addProduct, updateProduct } from "@/api/demo/product";
|
||||
import { DemoProductVO, DemoProductQuery, DemoProductForm } from '@/api/demo/product/types';
|
||||
|
||||
type ProductOption = {
|
||||
productId: number;
|
||||
productName: string;
|
||||
children?: ProductOption[];
|
||||
};
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
|
||||
const { sys_common_status } = toRefs<any>(proxy?.useDict('sys_common_status'));
|
||||
|
||||
const productList = ref<DemoProductVO[]>([]);
|
||||
const productOptions = ref<ProductOption[]>([]);
|
||||
const buttonLoading = ref(false);
|
||||
const showSearch = ref(true);
|
||||
const isExpandAll = ref(true);
|
||||
const loading = ref(false);
|
||||
|
||||
const queryFormRef = ref<ElFormInstance>();
|
||||
const productFormRef = ref<ElFormInstance>();
|
||||
const productTableRef = ref<ElTableInstance>()
|
||||
|
||||
const dialog = reactive<DialogOption>({
|
||||
visible: false,
|
||||
title: ''
|
||||
});
|
||||
|
||||
|
||||
const initFormData: DemoProductForm = {
|
||||
productId: undefined,
|
||||
parentId: undefined,
|
||||
productName: undefined,
|
||||
orderNum: undefined,
|
||||
status: undefined,
|
||||
version: 0,
|
||||
};
|
||||
|
||||
const data = reactive<PageData<DemoProductForm, DemoProductQuery>>({
|
||||
form: {...initFormData},
|
||||
queryParams: {
|
||||
productName: undefined,
|
||||
status: undefined,
|
||||
params: {
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
parentId: [
|
||||
{ required: true, message: "父产品id不能为空", trigger: "blur" }
|
||||
],
|
||||
productName: [
|
||||
{ required: true, message: "产品名称不能为空", trigger: "blur" }
|
||||
],
|
||||
orderNum: [
|
||||
{ required: true, message: "显示顺序不能为空", trigger: "blur" }
|
||||
],
|
||||
status: [
|
||||
{ required: true, message: "产品状态不能为空", trigger: "change" }
|
||||
],
|
||||
}
|
||||
});
|
||||
|
||||
const { queryParams, form, rules } = toRefs(data);
|
||||
|
||||
/** 查询产品树列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true;
|
||||
const res = await listProduct(queryParams.value);
|
||||
const data = proxy?.handleTree<DemoProductVO>(res.data, 'productId', 'parentId');
|
||||
if (data) {
|
||||
productList.value = data;
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 查询产品树下拉树结构 */
|
||||
const getTreeselect = async () => {
|
||||
const res = await listProduct();
|
||||
productOptions.value = [];
|
||||
const data: ProductOption = { productId: 0, productName: '顶级节点', children: [] };
|
||||
data.children = proxy?.handleTree<ProductOption>(res.data, 'productId', 'parentId');
|
||||
productOptions.value.push(data);
|
||||
};
|
||||
|
||||
// 取消按钮
|
||||
const cancel = () => {
|
||||
reset();
|
||||
dialog.visible = false;
|
||||
};
|
||||
|
||||
// 表单重置
|
||||
const reset = () => {
|
||||
form.value = {...initFormData}
|
||||
productFormRef.value?.resetFields();
|
||||
};
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
getList();
|
||||
};
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value?.resetFields();
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/** 新增按钮操作 */
|
||||
const handleAdd = (row?: DemoProductVO) => {
|
||||
reset();
|
||||
getTreeselect();
|
||||
if (row != null && row.productId) {
|
||||
form.value.parentId = row.productId;
|
||||
} else {
|
||||
form.value.parentId = 0;
|
||||
}
|
||||
dialog.visible = true;
|
||||
dialog.title = '添加产品树';
|
||||
};
|
||||
|
||||
/** 展开/折叠操作 */
|
||||
const handleToggleExpandAll = () => {
|
||||
isExpandAll.value = !isExpandAll.value;
|
||||
toggleExpandAll(productList.value, isExpandAll.value)
|
||||
};
|
||||
|
||||
/** 展开/折叠操作 */
|
||||
const toggleExpandAll = (data: DemoProductVO[], status: boolean) => {
|
||||
data.forEach((item) => {
|
||||
productTableRef.value?.toggleRowExpansion(item, status)
|
||||
if (item.children && item.children.length > 0) toggleExpandAll(item.children, status)
|
||||
})
|
||||
};
|
||||
|
||||
/** 修改按钮操作 */
|
||||
const handleUpdate = async (row: DemoProductVO) => {
|
||||
reset();
|
||||
await getTreeselect();
|
||||
if (row != null) {
|
||||
form.value.parentId = row.parentId;
|
||||
}
|
||||
const res = await getProduct(row.productId);
|
||||
Object.assign(form.value, res.data);
|
||||
dialog.visible = true;
|
||||
dialog.title = '修改产品树';
|
||||
};
|
||||
|
||||
/** 提交按钮 */
|
||||
const submitForm = () => {
|
||||
productFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
buttonLoading.value = true;
|
||||
if (form.value.productId) {
|
||||
await updateProduct(form.value).finally(() => buttonLoading.value = false);
|
||||
} else {
|
||||
await addProduct(form.value).finally(() => buttonLoading.value = false);
|
||||
}
|
||||
proxy?.$modal.msgSuccess('操作成功');
|
||||
dialog.visible = false;
|
||||
getList();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (row: DemoProductVO) => {
|
||||
await proxy?.$modal.confirm('是否确认删除产品树编号为"' + row.productId + '"的数据项?');
|
||||
loading.value = true;
|
||||
await delProduct(row.productId).finally(() => loading.value = false);
|
||||
await getList();
|
||||
proxy?.$modal.msgSuccess('删除成功');
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
310
src/views/demo/student/index.vue
Normal file
310
src/views/demo/student/index.vue
Normal file
@ -0,0 +1,310 @@
|
||||
<template>
|
||||
<div class="p-2">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||
<div class="search" v-show="showSearch">
|
||||
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
|
||||
<el-form-item label="学生名称" prop="studentName">
|
||||
<el-input v-model="queryParams.studentName" placeholder="请输入学生名称" clearable style="width: 240px" @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item label="年龄" prop="studentAge">
|
||||
<el-input
|
||||
v-model="queryParams.studentAge"
|
||||
placeholder="请输入年龄"
|
||||
clearable
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['demo:student:add']">新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['demo:student:edit']">修改</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['demo:student:remove']">删除</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['demo:student:export']">导出</el-button>
|
||||
</el-col>
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<el-table v-loading="loading" :data="studentList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="编号" align="center" prop="studentId" v-if="false" />
|
||||
<el-table-column label="学生名称" align="center" prop="studentName" />
|
||||
<el-table-column label="年龄" align="center" prop="studentAge" />
|
||||
<el-table-column label="爱好" align="center" prop="studentHobby">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="sys_student_hobby" :value="scope.row.studentHobby"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="性别" align="center" prop="studentSex">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="sys_user_gender" :value="scope.row.studentSex"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" align="center" prop="studentStatus">
|
||||
<template #default="scope">
|
||||
<dict-tag :options="sys_student_status" :value="scope.row.studentStatus"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="生日" align="center" prop="studentBirthday" width="180">
|
||||
<template #default="scope">
|
||||
<span>{{ parseTime(scope.row.studentBirthday, '{y}-{m}-{d}') }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-tooltip content="修改" placement="top">
|
||||
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['demo:student:edit']"></el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip content="删除" placement="top">
|
||||
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['demo:student:remove']"></el-button>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNum"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</el-card>
|
||||
<!-- 添加或修改学生信息表对话框 -->
|
||||
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||
<el-form ref="studentFormRef" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="学生名称" prop="studentName">
|
||||
<el-input v-model="form.studentName" placeholder="请输入学生名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="年龄" prop="studentAge">
|
||||
<el-input v-model="form.studentAge" placeholder="请输入年龄" />
|
||||
</el-form-item>
|
||||
<el-form-item label="爱好" prop="studentHobby">
|
||||
<el-select v-model="form.studentHobby" placeholder="请选择爱好">
|
||||
<el-option
|
||||
v-for="dict in sys_student_hobby"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="性别" prop="studentSex">
|
||||
<el-radio-group v-model="form.studentSex">
|
||||
<el-radio
|
||||
v-for="dict in sys_user_gender"
|
||||
:key="dict.value"
|
||||
:label="dict.value"
|
||||
>{{dict.label}}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="studentStatus">
|
||||
<el-select v-model="form.studentStatus" placeholder="请选择状态">
|
||||
<el-option
|
||||
v-for="dict in sys_student_status"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="生日" prop="studentBirthday">
|
||||
<el-date-picker clearable
|
||||
v-model="form.studentBirthday"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
placeholder="请选择生日">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item label="乐观锁" prop="version" v-show="false">
|
||||
<el-input v-model="form.version" placeholder="请输入乐观锁" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="DemoStudent" lang="ts">
|
||||
import { listStudent, getStudent, delStudent, addStudent, updateStudent } from '@/api/demo/student';
|
||||
import { DemoStudentVO, DemoStudentQuery, DemoStudentForm } from '@/api/demo/student/types';
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const { sys_student_status, sys_user_gender, sys_student_hobby } = toRefs<any>(proxy?.useDict('sys_student_status', 'sys_user_gender', 'sys_student_hobby'));
|
||||
|
||||
const studentList = ref<DemoStudentVO[]>([]);
|
||||
const buttonLoading = ref(false);
|
||||
const loading = ref(true);
|
||||
const showSearch = ref(true);
|
||||
const ids = ref<Array<string | number>>([]);
|
||||
const single = ref(true);
|
||||
const multiple = ref(true);
|
||||
const total = ref(0);
|
||||
|
||||
const queryFormRef = ref<ElFormInstance>();
|
||||
const studentFormRef = ref<ElFormInstance>();
|
||||
|
||||
const dialog = reactive<DialogOption>({
|
||||
visible: false,
|
||||
title: ''
|
||||
});
|
||||
|
||||
const initFormData: DemoStudentForm = {
|
||||
studentId: undefined,
|
||||
studentName: undefined,
|
||||
studentAge: undefined,
|
||||
studentHobby: undefined,
|
||||
studentSex: undefined,
|
||||
studentStatus: undefined,
|
||||
studentBirthday: undefined,
|
||||
version: 0,
|
||||
};
|
||||
const data = reactive<PageData<DemoStudentForm, DemoStudentQuery>>({
|
||||
form: {...initFormData},
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
studentName: undefined,
|
||||
studentStatus: undefined,
|
||||
params: {
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
studentName: [
|
||||
{ required: true, message: "学生名称不能为空", trigger: "blur" }
|
||||
],
|
||||
studentAge: [
|
||||
{ required: true, message: "年龄不能为空", trigger: "blur" }
|
||||
],
|
||||
studentHobby: [
|
||||
{ required: true, message: "爱好不能为空", trigger: "change" }
|
||||
],
|
||||
studentSex: [
|
||||
{ required: true, message: "性别不能为空", trigger: "change" }
|
||||
],
|
||||
studentStatus: [
|
||||
{ required: true, message: "状态不能为空", trigger: "change" }
|
||||
],
|
||||
studentBirthday: [
|
||||
{ required: true, message: "生日不能为空", trigger: "blur" }
|
||||
],
|
||||
}
|
||||
});
|
||||
|
||||
const { queryParams, form, rules } = toRefs(data);
|
||||
|
||||
/** 查询学生信息表列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true;
|
||||
const res = await listStudent(queryParams.value);
|
||||
studentList.value = res.rows;
|
||||
total.value = res.total;
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
/** 取消按钮 */
|
||||
const cancel = () => {
|
||||
reset();
|
||||
dialog.visible = false;
|
||||
};
|
||||
|
||||
/** 表单重置 */
|
||||
const reset = () => {
|
||||
form.value = {...initFormData};
|
||||
studentFormRef.value?.resetFields();
|
||||
};
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.value.pageNum = 1;
|
||||
getList();
|
||||
};
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value?.resetFields();
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/** 多选框选中数据 */
|
||||
const handleSelectionChange = (selection: DemoStudentVO[]) => {
|
||||
ids.value = selection.map(item => item.studentId);
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
};
|
||||
|
||||
/** 新增按钮操作 */
|
||||
const handleAdd = () => {
|
||||
reset();
|
||||
dialog.visible = true;
|
||||
dialog.title = "添加学生信息表";
|
||||
};
|
||||
|
||||
/** 修改按钮操作 */
|
||||
const handleUpdate = async (row?: DemoStudentVO) => {
|
||||
reset();
|
||||
const _studentId = row?.studentId || ids.value[0]
|
||||
const res = await getStudent(_studentId);
|
||||
Object.assign(form.value, res.data);
|
||||
dialog.visible = true;
|
||||
dialog.title = "修改学生信息表";
|
||||
};
|
||||
|
||||
/** 提交按钮 */
|
||||
const submitForm = () => {
|
||||
studentFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
buttonLoading.value = true;
|
||||
if (form.value.studentId) {
|
||||
await updateStudent(form.value).finally(() => buttonLoading.value = false);
|
||||
} else {
|
||||
await addStudent(form.value).finally(() => buttonLoading.value = false);
|
||||
}
|
||||
proxy?.$modal.msgSuccess("修改成功");
|
||||
dialog.visible = false;
|
||||
await getList();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (row?: DemoStudentVO) => {
|
||||
const _studentIds = row?.studentId || ids.value;
|
||||
await proxy?.$modal.confirm('是否确认删除学生信息表编号为"' + _studentIds + '"的数据项?').finally(() => loading.value = false);
|
||||
await delStudent(_studentIds);
|
||||
proxy?.$modal.msgSuccess("删除成功");
|
||||
await getList();
|
||||
};
|
||||
|
||||
/** 导出按钮操作 */
|
||||
const handleExport = () => {
|
||||
proxy?.download('demo/student/export', {
|
||||
...queryParams.value
|
||||
}, `student_${new Date().getTime()}.xlsx`)
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
@ -368,7 +368,7 @@ const handleDeleteGoods = () => {
|
||||
}
|
||||
|
||||
/** 复选框选中数据 */
|
||||
const handleGoodsSelectionChange = (selection: goodsVO[]) => {
|
||||
const handleGoodsSelectionChange = (selection: GoodsVO[]) => {
|
||||
checkedGoods.value = selection.map(item => item.index)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user