Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat][UI] Add user delete, disable and enable function in the project. #2795

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions seatunnel-ui/src/service/script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/

import { axios } from '@/service/service'
import type {
ScriptList,
ScriptAdd
} from '@/service/script/types'
import type { ScriptList, ScriptAdd } from '@/service/script/types'

export function scriptList(params: ScriptList): any {
return axios({
Expand Down
5 changes: 1 addition & 4 deletions seatunnel-ui/src/service/script/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ interface ScriptAdd {
type: string
}

export {
ScriptList,
ScriptAdd
}
export { ScriptList, ScriptAdd }
4 changes: 3 additions & 1 deletion seatunnel-ui/src/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const err = (err: AxiosError): Promise<AxiosError> => {

service.interceptors.request.use((config: AxiosRequestConfig<any>) => {
if (Object.keys(userStore.getUserInfo).length > 0) {
config.headers && (config.headers.token = (userStore.getUserInfo as UserDetail).token as string)
config.headers &&
(config.headers.token = (userStore.getUserInfo as UserDetail)
.token as string)
}

return config
Expand Down
2 changes: 1 addition & 1 deletion seatunnel-ui/src/service/task/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ export function taskInstanceKill(taskInstanceId: number): any {
url: `/task/${taskInstanceId}`,
method: 'patch'
})
}
}
2 changes: 1 addition & 1 deletion seatunnel-ui/src/service/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ type ResponseTable<T> = ResponseBasic<{
data: T
}>

export { ResponseTable }
export { ResponseTable }
2 changes: 1 addition & 1 deletion seatunnel-ui/src/service/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ export function userEnable(userId: number): any {
url: `/user/${userId}/enable`,
method: 'patch'
})
}
}
2 changes: 1 addition & 1 deletion seatunnel-ui/src/service/user/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ interface UserDetail extends UserLogin {
updateTime?: any | null
}

export { UserList, UserLogin, UserDetail }
export { UserList, UserLogin, UserDetail }
2 changes: 1 addition & 1 deletion seatunnel-ui/src/store/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ export const useUserStore = defineStore({
this.userInfo = userInfo
}
}
})
})
2 changes: 1 addition & 1 deletion seatunnel-ui/src/store/user/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ interface UserState {
userInfo: UserDetail | {}
}

export { UserState }
export { UserState }
6 changes: 5 additions & 1 deletion seatunnel-ui/src/views/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ const Login = defineComponent({
},
render() {
return (
<NSpace justify='center' align='center' class='w-full h-screen bg-blue-400'>
<NSpace
justify='center'
align='center'
class='w-full h-screen bg-blue-400'
>
<div class='w-96 bg-white px-10 py-8'>
<h2 class='text-2xl mb-6'>{this.t('login.login_to_sea_tunnel')}</h2>
<NForm rules={this.rules} ref='loginFormRef'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const DeleteModal = defineComponent({
ctx.emit('cancelModal', props.showModal)
}

const handleConfirm = () => {}
const handleConfirm = () => {
ctx.emit('confirmModal')
}

return { t, handleCancel, handleConfirm }
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ const FormModal = defineComponent({
emits: ['cancelModal', 'confirmModal'],
setup(props, ctx) {
const { t } = useI18n()
const { state, handleValidate } = useFormModal(props, ctx)
const { state, handleValidate, clearForm } = useFormModal(props, ctx)
const trim = getCurrentInstance()?.appContext.config.globalProperties.trim

const handleCancel = () => {
if (props.status === 0) {
}
clearForm()
ctx.emit('cancelModal', props.showModal)
}

Expand Down Expand Up @@ -133,9 +132,9 @@ const FormModal = defineComponent({
</NSpace>
</NFormItem>
<NFormItem label={this.t('user_manage.status')} path='status'>
<NRadioGroup v-model={[this.model.state, 'value']}>
<NRadio value={0}>{this.t('user_manage.active')}</NRadio>
<NRadio value={1}>{this.t('user_manage.inactive')}</NRadio>
<NRadioGroup v-model={[this.model.status, 'value']}>
<NRadio value={0}>{this.t('user_manage.enable')}</NRadio>
<NRadio value={1}>{this.t('user_manage.disable')}</NRadio>
</NRadioGroup>
</NFormItem>
</NForm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { reactive, ref, SetupContext } from 'vue'
import { useI18n } from 'vue-i18n'
import utils from '@/utils'
import { userAdd, userUpdate } from '@/service/user'

export function useFormModal(
props: any,
Expand Down Expand Up @@ -46,15 +46,30 @@ export function useFormModal(
}
})

const handleValidate = (status: number) => {
const handleValidate = (status: 0 | 1) => {
state.userManageForm.validate((errors: any) => {
if (!errors) {
ctx.emit('confirmModal', props.showModal)
} else {
return
}
if (errors) return

status ? handleAdd() : handleUpdate()
ctx.emit('confirmModal', props.showModal)
clearForm()
})
}

return { state, handleValidate }
const clearForm = () => {
state.model.id = ''
state.model.username = ''
state.model.password = ''
state.model.status = 0
}

const handleAdd = () => {
//userAdd().then(() => {
//
//})
}

const handleUpdate = () => {}

return { state, handleValidate, clearForm }
}
7 changes: 2 additions & 5 deletions seatunnel-ui/src/views/user-manage/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import DeleteModal from './components/delete-modal'
const UserManageList = defineComponent({
setup() {
const { t } = useI18n()
const { state, createColumns, getTableData } = useTable()
const { state, createColumns, getTableData, handleConfirmDeleteModal } =
useTable()

const handleFormModal = () => {
state.showFormModal = true
Expand All @@ -44,10 +45,6 @@ const UserManageList = defineComponent({
state.showDeleteModal = false
}

const handleConfirmDeleteModal = () => {
state.showDeleteModal = false
}

const handlePageSize = () => {
state.pageNo = 1
requestData()
Expand Down
66 changes: 41 additions & 25 deletions seatunnel-ui/src/views/user-manage/list/use-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { reactive, ref, h } from 'vue'
import { useAsyncState } from '@vueuse/core'
import { useI18n } from 'vue-i18n'
import { NSpace, NButton } from 'naive-ui'
import { userList, userDelete } from '@/service/user'
import { userList, userDelete, userEnable, userDisable } from '@/service/user'
import type { ResponseTable } from '@/service/types'
import type { UserDetail } from '@/service/user/types'

Expand All @@ -44,10 +44,6 @@ export function useTable() {
title: t('user_manage.username'),
key: 'name'
},
{
title: t('user_manage.status'),
key: 'status'
},
{
title: t('user_manage.create_time'),
key: 'createTime'
Expand All @@ -59,10 +55,14 @@ export function useTable() {
{
title: t('user_manage.operation'),
key: 'operation',
render: (row: any) =>
render: (row: UserDetail) =>
h(NSpace, null, {
default: () => [
h(NButton, { text: true }, t('user_manage.enable')),
h(
NButton,
{ text: true, onClick: () => handleStatus(row) },
row.status ? t('user_manage.enable') : t('user_manage.disable')
),
h(
NButton,
{ text: true, onClick: () => handleEdit(row) },
Expand All @@ -79,39 +79,55 @@ export function useTable() {
]
}

const handleEdit = (row: any) => {
const handleStatus = (row: UserDetail) => {
const req = row.status ? userEnable : userDisable
req(row.id as number).then(() => {
getTableData({
pageSize: state.pageSize,
pageNo: state.pageNo
})
})
}

const handleEdit = (row: UserDetail) => {
state.showFormModal = true
state.status = 1
state.row = row
}

const handleDelete = (row: any) => {
//if (state.tableData.length === 1 && state.pageNo > 1) {
// --state.pageNo
//}
//
//userDelete(row.id).then(() => {
// getTableData({
// pageSize: state.pageSize,
// pageNo: state.pageNo
// })
//})
const handleDelete = (row: UserDetail) => {
state.showDeleteModal = true
state.row = row
}

const handleConfirmDeleteModal = () => {
if (state.tableData.length === 1 && state.pageNo > 1) {
--state.pageNo
}

userDelete((state.row as UserDetail).id as number).then(() => {
state.showDeleteModal = false
getTableData({
pageSize: state.pageSize,
pageNo: state.pageNo
})
})
}

const getTableData = (params: any) => {
if (state.loading) return
state.loading = true
useAsyncState(
userList({ ...params }).then((res: ResponseTable<Array<UserDetail> | []>) => {
state.tableData = res.data.data
state.totalPage = res.data.totalPage
state.loading = false
}),
userList({ ...params }).then(
(res: ResponseTable<Array<UserDetail> | []>) => {
state.tableData = res.data.data
state.totalPage = res.data.totalPage
state.loading = false
}
),
{}
)
}

return { state, createColumns, getTableData }
return { state, createColumns, getTableData, handleConfirmDeleteModal }
}