Merge pull request '完成编辑按钮与后端接口的对接' (#31) from Brunch_LPQ into main

pull/38/head
ppnwsfegt 2 months ago
commit 994dc0be70

@ -47,7 +47,7 @@ public class SysUserController {
@PutMapping
public ResultVo editUser(@RequestBody SysUser sysUser){
if(sysUserService.updateById(sysUser)){
return ResultUtils.success("编辑用户成功!");
return ResultUtils.success("编辑用户成功!", sysUser);
}
return ResultUtils.error("编辑用户失败!");
}

@ -10,3 +10,8 @@ export const addUserApi = (parm:UserModel)=>{
export const getListApi = (parm:ListUserParm)=>{
return http.get("api/user/list", parm)
}
// 编辑接口
export const editUserApi = (parm:UserModel)=>{
return http.put("/api/user", parm)
}

@ -9,6 +9,7 @@ export type ListUserParm = {
// 定义表单数据类型
export type UserModel = {
type: string;
userId: string;
username: string;
password: string;

@ -1,21 +1,25 @@
import type { UserModel } from "@/api/user/userModel";
import { EditType } from "../../type/baseType";
import { ref } from "vue"
// 抽取增删改的业务操作
export default function useUser() {
// 获取AddUser里面的show方法
const showBtn = ref<{ show: (title: string, width: number, height: number) => {} }>();
const showBtn = ref<{ show: (title: string, type: string, width?: number, height?: number, row?:UserModel) => {} }>();
// 增
const addBtn = () => {
showBtn.value?.show("新增", 630, 180)
showBtn.value?.show("新增", EditType.ADD, 630, 180)
}
// 删
const deleteBtn = () => {
}
// 改
const editBtn = () => {
// 传递row参数将旧数据传递出去方便编辑
const editBtn = (row: UserModel) => {
console.log(row)
showBtn.value?.show("编辑", EditType.EDIT, 630, 180, row)
}
return {

@ -0,0 +1,12 @@
import { getCurrentInstance } from "vue";
import type { ComponentInternalInstance } from "vue";
export default function useInstance() {
const { appContext, proxy } = getCurrentInstance() as ComponentInternalInstance
// 获取全局属性
const global = appContext.config.globalProperties
return {
global,
proxy
}
}

@ -14,6 +14,8 @@ import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
// createApp(App).mount('#app')
// 引入消息弹出框组件
import myConfirm from './utils/myConfirm'
const pinia = createPinia()
// 挂载路由
@ -30,3 +32,6 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
// 全局注册消息弹出框组件
app.config.globalProperties.$myconfirm = myConfirm

@ -0,0 +1,8 @@
// 通用函数类型
export type FuncList = () => any
// 新增和编辑的状态
export enum EditType{
ADD = '0', //新增
EDIT = '1' //编辑
}

@ -0,0 +1,12 @@
// 从Element-plus中导入消息弹出框组件
import { ElMessageBox } from 'element-plus'
export default function myConfirm(text: string): Promise<boolean> {
return ElMessageBox.confirm(text, '系统提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => true)
.catch(() => false)
}

@ -70,25 +70,38 @@
import SysDialog from '@/components/SysDialog.vue';
//
import useDialog from '@/hooks/useDialog';
import { ref, reactive } from 'vue';
import { ref, reactive, nextTick } from 'vue';
// UserModel
import type { UserModel } from '@/api/user/userModel';
import type { FormInstance } from 'element-plus';
import { ElMessage, type FormInstance } from 'element-plus';
// post
import { addUserApi } from '../../api/user/index';
import { addUserApi, editUserApi } from '../../api/user/index';
import { EditType } from '../../type/baseType';
//
const { dialog, onClose, onConfirm, onShow } = useDialog()
//
const show = (title: string, width: number, height: number) => {
// dialog.title:
const show = (title: string, type: string, width: number, height: number, row?: UserModel) => {
onShow(title, width, height)
// dialog.visible = true;
//
addFormRef.value?.resetFields()
//
if (row) {
nextTick(() => {
Object.assign(addModel, row)
})
}
//
addModel.type = type
}
//
@ -98,6 +111,7 @@ defineExpose({
//
const addModel = reactive<UserModel>({
type: "",
userId: "",
username: "",
password: "",
@ -139,14 +153,27 @@ const rules = reactive({
}]
})
//
const emits = defineEmits(['onFresh'])
//
const commit = () => {
addFormRef.value?.validate(async(valid) => {
if(valid){
addFormRef.value?.validate(async (valid) => {
if (valid) {
// addUserApi
let res = await addUserApi(addModel)
let res = null
if(addModel.type == EditType.ADD){
res = await addUserApi(addModel)
}else{
res = await editUserApi(addModel)
}
console.log(res)
if(res && res.code == 200){
if (res && res.code == 200) {
//
ElMessage.success(res.msg)
//
// getList()
emits('onFresh')
onConfirm()
}

@ -32,8 +32,8 @@
<!-- 为表格添加编辑删除按钮 -->
<el-table-column label="操作" min-width="100" align="center">
<template #default>
<el-button type="primary" size="default" @click="editBtn" icon="Edit">
<template #default="scoped">
<el-button type="primary" size="default" @click="editBtn(scoped.row)" icon="Edit">
编辑
</el-button>
<el-button type="danger" size="default" @click="deleteBtn" icon="Delete">删除</el-button>
@ -51,18 +51,17 @@
</el-main>
<!-- 新增编辑按钮弹框 -->
<AddUser ref="showBtn"></AddUser>
<AddUser ref="showBtn" @onFresh="getList"></AddUser>
</template>
<script setup lang="ts">
import { Search, Close, Plus, Edit, Delete } from '@element-plus/icons-vue'
import { Search, Close, Plus } from '@element-plus/icons-vue'
// useUserTable,
// vite-env.d.ts
import useUserTable from '@/compositions/user/useUserTable';
// onMounted
import { onMounted } from 'vue';
//
const { listParm,
@ -82,10 +81,6 @@ const { showBtn, addBtn, deleteBtn, editBtn } = useUser()
// AddUser,
import AddUser from './AddUser.vue';
//
onMounted(() => {
getList()
})
</script>
<style scoped></style>

@ -21,6 +21,19 @@ interface PromiseConstructor {
// 添加全局 Promise 声明
declare var Promise: PromiseConstructor;
// 扩展全局 Object 接口声明
interface ObjectConstructor {
/**
*
* @param target
* @param sources
*/
assign<T, U>(target: T, source: U): T & U;
assign<T, U, V>(target: T, source1: U, source2: V): T & U & V;
assign<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
assign(target: object, ...sources: any[]): any;
}
// 声明 Vue 文件模块
declare module '*.vue' {
import type { DefineComponent } from 'vue'
@ -69,6 +82,7 @@ declare module '@/api/user/userModel' {
}
export type UserModel = {
type: string,
userId: string;
username: string;
password: string;
@ -76,5 +90,5 @@ declare module '@/api/user/userModel' {
email: string;
sex: string;
name: string;
}
}
}

@ -12,7 +12,7 @@
"@/api/*": ["src/api/*"]
},
//
"lib": ["ES2015", "ES2015.Promise", "DOM", "DOM.Iterable", "ESNext"],
"lib": ["ES2020", "ES2015.Promise", "DOM", "DOM.Iterable", "ESNext"],
//
"module": "ESNext",

Loading…
Cancel
Save