diff --git a/gpt-vue/projects/vue-admin/src/composables/useCustomFormPopup.ts b/gpt-vue/projects/vue-admin/src/composables/useCustomFormPopup.ts new file mode 100644 index 00000000..298e9556 --- /dev/null +++ b/gpt-vue/projects/vue-admin/src/composables/useCustomFormPopup.ts @@ -0,0 +1,39 @@ +import usePopup from "./usePopup"; +import { Message } from "@arco-design/web-vue"; +import type { Component } from "vue"; +import type { BaseResponse } from "@gpt-vue/packages/type"; +interface Arg { + reload?: () => void; + record?: Record; +} +export default function ( + node: Component, + api: (params?: any) => Promise> +): (arg: Arg) => void { + const nodeProps = (arg: Arg[]) => { + return { + data: arg[0].record || {}, + }; + }; + + const popupProps = (arg: Arg[], getExposed) => { + return { + width: 700, + onBeforeOk: async () => { + const exposed = getExposed(); + const validateRes = await exposed?.formRef.value.validate(); + if (validateRes) { + return false; + } + const { code } = await api(exposed?.form.value); + if (code === 0) { + Message.success("操作成功"); + } + arg[0]?.reload?.(); + return code === 0; + }, + }; + }; + + return usePopup(node, { nodeProps, popupProps }); +} diff --git a/gpt-vue/projects/vue-admin/src/views/User/UserContainer.vue b/gpt-vue/projects/vue-admin/src/views/User/UserContainer.vue index 07acb511..438459fc 100644 --- a/gpt-vue/projects/vue-admin/src/views/User/UserContainer.vue +++ b/gpt-vue/projects/vue-admin/src/views/User/UserContainer.vue @@ -3,11 +3,10 @@ import SearchTable from "@/components/SearchTable/SearchTable.vue"; import type { SearchTableColumns } from "@/components/SearchTable/type"; import { getList, save as saveApi, deletApi, resetPassword } from "./api"; import UserForm from "./UserForm.vue"; -import { ref } from "vue"; import { Message } from "@arco-design/web-vue"; import { dateFormat } from "@gpt-vue/packages/utils"; -import usePopup from "@/composables/usePopup"; import UserPassword from "./UserPassword.vue"; +import useCustomFormPopup from "@/composables/useCustomFormPopup"; const columns: SearchTableColumns[] = [ { title: "账号", @@ -56,38 +55,8 @@ const columns: SearchTableColumns[] = [ ]; //弹窗 - -const popup = (node, api) => { - const nodeProps = (arg) => { - return { - data: arg[0].record, - }; - }; - - const popupProps = (arg, getExposed) => { - return { - width: 700, - onBeforeOk: async () => { - const exposed = getExposed(); - const validateRes = await exposed?.formRef.value.validate(); - if (validateRes) { - return false; - } - const res = await api(exposed?.form.value); - if (res.code === 0) { - Message.success("操作成功"); - } - arg[0].reload(); - return res.code === 0; - }, - }; - }; - - return usePopup(node, { nodeProps, popupProps }); -}; - -const editModal = popup(UserForm, saveApi); -const password = popup(UserPassword, resetPassword); +const editModal = useCustomFormPopup(UserForm, saveApi); +const password = useCustomFormPopup(UserPassword, resetPassword); const handleDelete = async ({ id }: { id: string }, reload) => { const res = await deletApi(id); diff --git a/gpt-vue/projects/vue-admin/src/views/User/UserForm.vue b/gpt-vue/projects/vue-admin/src/views/User/UserForm.vue index cc4a66ce..b5b8da7e 100644 --- a/gpt-vue/projects/vue-admin/src/views/User/UserForm.vue +++ b/gpt-vue/projects/vue-admin/src/views/User/UserForm.vue @@ -79,7 +79,6 @@ const props = defineProps({ const formRef = ref(); const form = ref({ - id: "", username: "", password: "", calls: "",