|
|
|
@ -1,19 +1,36 @@
|
|
|
|
|
import type { UserModel } from "@/api/user/userModel";
|
|
|
|
|
import { EditType } from "../../type/baseType";
|
|
|
|
|
import type { FuncList } from "../../type/baseType";
|
|
|
|
|
import { ref } from "vue"
|
|
|
|
|
import useInstance from "@/hooks/useInstance";
|
|
|
|
|
import { deleteUserApi } from "../../api/user/index";
|
|
|
|
|
import { ElMessage } from "element-plus";
|
|
|
|
|
|
|
|
|
|
// 抽取增删改的业务操作
|
|
|
|
|
export default function useUser() {
|
|
|
|
|
export default function useUser(getList:FuncList) {
|
|
|
|
|
const { global } = useInstance()
|
|
|
|
|
|
|
|
|
|
// 获取AddUser里面的show方法
|
|
|
|
|
const showBtn = ref<{ show: (title: string, type: string, width?: number, height?: number, row?:UserModel) => {} }>();
|
|
|
|
|
const showBtn = ref<{ show: (title: string, type: string, width?: number, height?: number, row?: UserModel) => {} }>();
|
|
|
|
|
|
|
|
|
|
// 增
|
|
|
|
|
const addBtn = () => {
|
|
|
|
|
showBtn.value?.show("新增", EditType.ADD, 630, 180)
|
|
|
|
|
}
|
|
|
|
|
// 删
|
|
|
|
|
const deleteBtn = () => {
|
|
|
|
|
const deleteBtn = async (row: UserModel) => {
|
|
|
|
|
let confirm = await global.$myconfirm('确定删除该数据吗?')
|
|
|
|
|
|
|
|
|
|
// 判断confirm返回true(用户确定删除)就进行删除(调用删除api)
|
|
|
|
|
if (confirm) {
|
|
|
|
|
let res = await deleteUserApi(row.userId)
|
|
|
|
|
if (res && res.code == 200) {
|
|
|
|
|
// 删除成功信息提示
|
|
|
|
|
ElMessage.success(res.msg)
|
|
|
|
|
// 删除后刷新列表
|
|
|
|
|
getList()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 改
|
|
|
|
|
// 传递row参数,将旧数据传递出去方便编辑
|
|
|
|
|