This is an automated email from the ASF dual-hosted git repository.

kirs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-seatunnel.git


The following commit(s) were added to refs/heads/dev by this push:
     new bc21938e4 [Feat][UI] Add user add and update function in the project. 
(#2810)
bc21938e4 is described below

commit bc21938e407339a5b10c428fba19ed7387e3c272
Author: songjianet <[email protected]>
AuthorDate: Tue Sep 20 17:51:44 2022 +0800

    [Feat][UI] Add user add and update function in the project. (#2810)
    
    * [Feat][UI] Add user add and update function in the project.
    
    * [Feat][UI] Add user add and update function in the project.
---
 seatunnel-ui/src/service/types.ts                  |  2 --
 seatunnel-ui/src/service/user/types.ts             |  4 ++--
 .../user-manage/list/components/form-modal.tsx     | 20 +++++++++++++---
 .../user-manage/list/components/use-form-modal.ts  | 28 +++++++++++++++-------
 seatunnel-ui/src/views/user-manage/list/index.tsx  |  2 ++
 .../src/views/user-manage/list/use-table.ts        |  6 +++--
 6 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/seatunnel-ui/src/service/types.ts 
b/seatunnel-ui/src/service/types.ts
index ce66f6c24..3bc79fff4 100644
--- a/seatunnel-ui/src/service/types.ts
+++ b/seatunnel-ui/src/service/types.ts
@@ -15,8 +15,6 @@
  * limitations under the License.
  */
 
-import { UserDetail } from '@/service/user/types'
-
 interface ResponseBasic<T> {
   code: number
   failed: boolean
diff --git a/seatunnel-ui/src/service/user/types.ts 
b/seatunnel-ui/src/service/user/types.ts
index 9583b4460..31ef9e563 100644
--- a/seatunnel-ui/src/service/user/types.ts
+++ b/seatunnel-ui/src/service/user/types.ts
@@ -27,8 +27,8 @@ interface UserLogin {
 }
 
 interface UserDetail extends UserLogin {
-  status: string
-  type: string
+  status: number
+  type?: number
   token?: string
   id?: number
   name?: string
diff --git a/seatunnel-ui/src/views/user-manage/list/components/form-modal.tsx 
b/seatunnel-ui/src/views/user-manage/list/components/form-modal.tsx
index 685c21c58..d95fc0f1c 100644
--- a/seatunnel-ui/src/views/user-manage/list/components/form-modal.tsx
+++ b/seatunnel-ui/src/views/user-manage/list/components/form-modal.tsx
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-import { defineComponent, getCurrentInstance, toRefs } from 'vue'
+import { defineComponent, getCurrentInstance, toRefs, watch } from 'vue'
 import {
   NForm,
   NFormItem,
@@ -56,7 +56,6 @@ const FormModal = defineComponent({
     const trim = getCurrentInstance()?.appContext.config.globalProperties.trim
 
     const handleCancel = () => {
-      clearForm()
       ctx.emit('cancelModal', props.showModal)
     }
 
@@ -64,6 +63,19 @@ const FormModal = defineComponent({
       handleValidate(props.status)
     }
 
+    watch(
+      () => props.showModal,
+      () => {
+        clearForm()
+        if (props.status === 1) {
+          state.model.id = props.row.id
+          state.model.username = props.row.name
+          state.model.status = props.row.status
+        }
+        state.rules.password.required = props.row.id === undefined
+      }
+    )
+
     return { t, ...toRefs(state), trim, handleCancel, handleConfirm }
   },
   render() {
@@ -77,7 +89,9 @@ const FormModal = defineComponent({
         show={this.showModal}
         onCancel={this.handleCancel}
         onConfirm={this.handleConfirm}
-        confirmDisabled={!this.model.username || !this.model.password}
+        confirmDisabled={
+          !this.model.username || (this.status === 0 && !this.model.password)
+        }
       >
         {{
           default: () => (
diff --git 
a/seatunnel-ui/src/views/user-manage/list/components/use-form-modal.ts 
b/seatunnel-ui/src/views/user-manage/list/components/use-form-modal.ts
index ff640c8b0..a35aac63e 100644
--- a/seatunnel-ui/src/views/user-manage/list/components/use-form-modal.ts
+++ b/seatunnel-ui/src/views/user-manage/list/components/use-form-modal.ts
@@ -46,13 +46,11 @@ export function useFormModal(
     }
   })
 
-  const handleValidate = (status: 0 | 1) => {
+  const handleValidate = (status: number) => {
     state.userManageForm.validate((errors: any) => {
       if (errors) return
 
-      status ? handleAdd() : handleUpdate()
-      ctx.emit('confirmModal', props.showModal)
-      clearForm()
+      status === 0 ? handleAdd() : handleUpdate()
     })
   }
 
@@ -64,12 +62,26 @@ export function useFormModal(
   }
 
   const handleAdd = () => {
-    //userAdd().then(() => {
-    //
-    //})
+    userAdd({
+      username: state.model.username,
+      password: state.model.password,
+      status: state.model.status,
+      type: 0
+    }).then(() => {
+      ctx.emit('confirmModal', props.showModal)
+    })
   }
 
-  const handleUpdate = () => {}
+  const handleUpdate = () => {
+    userUpdate(state.model.id, {
+      username: state.model.username,
+      password: state.model.password,
+      status: state.model.status,
+      type: 0
+    }).then(() => {
+      ctx.emit('confirmModal', props.showModal)
+    })
+  }
 
   return { state, handleValidate, clearForm }
 }
diff --git a/seatunnel-ui/src/views/user-manage/list/index.tsx 
b/seatunnel-ui/src/views/user-manage/list/index.tsx
index 8d5cb909b..4de902f71 100644
--- a/seatunnel-ui/src/views/user-manage/list/index.tsx
+++ b/seatunnel-ui/src/views/user-manage/list/index.tsx
@@ -31,6 +31,7 @@ const UserManageList = defineComponent({
     const handleFormModal = () => {
       state.showFormModal = true
       state.status = 0
+      state.row = {}
     }
 
     const handleCancelFormModal = () => {
@@ -39,6 +40,7 @@ const UserManageList = defineComponent({
 
     const handleConfirmFormModal = () => {
       state.showFormModal = false
+      requestData()
     }
 
     const handleCancelDeleteModal = () => {
diff --git a/seatunnel-ui/src/views/user-manage/list/use-table.ts 
b/seatunnel-ui/src/views/user-manage/list/use-table.ts
index 16eea81a7..f21e0a4dd 100644
--- a/seatunnel-ui/src/views/user-manage/list/use-table.ts
+++ b/seatunnel-ui/src/views/user-manage/list/use-table.ts
@@ -61,7 +61,9 @@ export function useTable() {
               h(
                 NButton,
                 { text: true, onClick: () => handleStatus(row) },
-                row.status ? t('user_manage.enable') : t('user_manage.disable')
+                row.status === 1
+                  ? t('user_manage.enable')
+                  : t('user_manage.disable')
               ),
               h(
                 NButton,
@@ -80,7 +82,7 @@ export function useTable() {
   }
 
   const handleStatus = (row: UserDetail) => {
-    const req = row.status ? userEnable : userDisable
+    const req = row.status === 1 ? userEnable : userDisable
     req(row.id as number).then(() => {
       getTableData({
         pageSize: state.pageSize,

Reply via email to