|
|
@@ -2,12 +2,11 @@
|
|
|
<div class="mediaList">
|
|
|
<Search :onClickSearch="onClickSearch" :onClickReset="onClickReset" />
|
|
|
<div class="mediaList-table">
|
|
|
- <a-table :columns="columns" :data-source="data.member" :pagination="paginationConfig" @change="refreshData"
|
|
|
- row-key="user_id" :rowClassName="(record, index) => ((index % 2) === 0 ? 'table-striped' : null)"
|
|
|
- :scroll="{ x: '100%', y: 600 }">
|
|
|
+ <a-table :scroll="{ x: '100%', y: 500 }" rowKey="user_id" :loading="state.listLoading" :columns="columns"
|
|
|
+ @change="refreshData" :rowClassName="rowClassName" :dataSource="state.list" :pagination="paginationConfig">
|
|
|
<template v-for="col in ['mqtt_username', 'mqtt_password']" #[col]="{ text, record }" :key="col">
|
|
|
<div>
|
|
|
- <a-input v-if="editableData[record.user_id]" v-model:value="editableData[record.user_id][col]"
|
|
|
+ <a-input v-if="state.editableData[record.user_id]" v-model:value="state.editableData[record.user_id][col]"
|
|
|
style="margin: -5px 0" />
|
|
|
<template v-else>
|
|
|
{{ text }}
|
|
|
@@ -16,14 +15,14 @@
|
|
|
</template>
|
|
|
<template #action="{ record }">
|
|
|
<div class="editable-row-operations">
|
|
|
- <span v-if="editableData[record.user_id]">
|
|
|
+ <span v-if="state.editableData[record.user_id]">
|
|
|
<a-tooltip title="确定">
|
|
|
<span @click="save(record)" style="color: #28d445;">
|
|
|
<CheckOutlined />
|
|
|
</span>
|
|
|
</a-tooltip>
|
|
|
<a-tooltip title="取消">
|
|
|
- <span @click="() => delete editableData[record.user_id]" class="ml15" style="color: #e70102;">
|
|
|
+ <span @click="() => delete state.editableData[record.user_id]" class="ml15" style="color: #e70102;">
|
|
|
<CloseOutlined />
|
|
|
</span>
|
|
|
</a-tooltip>
|
|
|
@@ -39,12 +38,11 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
+
|
|
|
<script lang="ts" setup>
|
|
|
import { message } from 'ant-design-vue'
|
|
|
-import { TableState } from 'ant-design-vue/lib/table/interface'
|
|
|
import { onMounted, reactive, UnwrapRef } from 'vue'
|
|
|
import Search from './components/Search.vue';
|
|
|
-import { IPage } from '/@/api/http/type'
|
|
|
import { getAllUsersInfo, updateUserInfo } from '/@/api/manage'
|
|
|
import { ELocalStorageKey } from '/@/types'
|
|
|
import { EditOutlined, CheckOutlined, CloseOutlined } from '@ant-design/icons-vue'
|
|
|
@@ -59,10 +57,53 @@ export interface Member {
|
|
|
mqtt_password: string
|
|
|
}
|
|
|
|
|
|
-interface MemberData {
|
|
|
- member: Member[]
|
|
|
+interface State {
|
|
|
+ listLoading: boolean,
|
|
|
+ list: Member[],
|
|
|
+ editableData: {
|
|
|
+ [key: string]: any,
|
|
|
+ },
|
|
|
}
|
|
|
|
|
|
+const state: State = reactive({
|
|
|
+ listLoading: false,
|
|
|
+ list: [],
|
|
|
+ editableData: {},
|
|
|
+})
|
|
|
+
|
|
|
+const paginationConfig = reactive({
|
|
|
+ pageSizeOptions: ['20', '50', '100'],
|
|
|
+ showQuickJumper: true,
|
|
|
+ showSizeChanger: true,
|
|
|
+ pageSize: 20,
|
|
|
+ current: 1,
|
|
|
+ total: 0
|
|
|
+})
|
|
|
+
|
|
|
+const workspaceId: string = localStorage.getItem(ELocalStorageKey.WorkspaceId)!
|
|
|
+
|
|
|
+const fetchList = async (query?: any) => {
|
|
|
+ state.listLoading = true;
|
|
|
+ try {
|
|
|
+ const res = await getAllUsersInfo(workspaceId, {
|
|
|
+ ...query,
|
|
|
+ page: paginationConfig.current,
|
|
|
+ page_size: paginationConfig.pageSize,
|
|
|
+ });
|
|
|
+ state.list = res.data.list;
|
|
|
+ paginationConfig.total = res.data.pagination.total
|
|
|
+ paginationConfig.current = res.data.pagination.page
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e);
|
|
|
+ } finally {
|
|
|
+ state.listLoading = false;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(async () => {
|
|
|
+ await fetchList()
|
|
|
+})
|
|
|
+
|
|
|
const columns = [
|
|
|
{
|
|
|
title: '用户名称',
|
|
|
@@ -106,55 +147,27 @@ const columns = [
|
|
|
}
|
|
|
]
|
|
|
|
|
|
-const data = reactive<MemberData>({
|
|
|
- member: []
|
|
|
-})
|
|
|
-
|
|
|
-const editableData: UnwrapRef<Record<string, Member>> = reactive({})
|
|
|
-
|
|
|
-const paginationConfig = reactive({
|
|
|
- pageSizeOptions: ['20', '50', '100'],
|
|
|
- showQuickJumper: true,
|
|
|
- showSizeChanger: true,
|
|
|
- pageSize: 20,
|
|
|
- current: 1,
|
|
|
- total: 0
|
|
|
-})
|
|
|
-
|
|
|
-type Pagination = TableState['pagination']
|
|
|
-
|
|
|
-const body: IPage = {
|
|
|
- page: 1,
|
|
|
- total: 0,
|
|
|
- page_size: 50
|
|
|
-}
|
|
|
-const workspaceId: string = localStorage.getItem(ELocalStorageKey.WorkspaceId)!
|
|
|
-
|
|
|
-onMounted(() => {
|
|
|
- getAllUsers(workspaceId, body)
|
|
|
-})
|
|
|
-
|
|
|
-function refreshData(page: Pagination) {
|
|
|
- body.page = page?.current!
|
|
|
- body.page_size = page?.pageSize!
|
|
|
- getAllUsers(workspaceId, body)
|
|
|
+const rowClassName = (record: any, index: number) => {
|
|
|
+ const className = []
|
|
|
+ if ((index & 1) === 0) {
|
|
|
+ className.push('table-striped')
|
|
|
+ }
|
|
|
+ return className.toString().replaceAll(',', ' ')
|
|
|
}
|
|
|
|
|
|
-function getAllUsers(workspaceId: string, page: IPage) {
|
|
|
- getAllUsersInfo(workspaceId, page).then(res => {
|
|
|
- const userList: Member[] = res.data.list
|
|
|
- data.member = userList
|
|
|
- paginationConfig.total = res.data.pagination.total
|
|
|
- paginationConfig.current = res.data.pagination.page
|
|
|
- })
|
|
|
+const refreshData = async (page: any) => {
|
|
|
+ paginationConfig.current = page?.current!
|
|
|
+ paginationConfig.pageSize = page?.pageSize!
|
|
|
+ await fetchList();
|
|
|
}
|
|
|
-
|
|
|
-function edit(record: Member) {
|
|
|
- editableData[record.user_id] = record
|
|
|
+// 点击编辑
|
|
|
+const edit = (record: Member) => {
|
|
|
+ state.editableData[record.user_id] = record;
|
|
|
}
|
|
|
|
|
|
-function save(record: Member) {
|
|
|
- delete editableData[record.user_id]
|
|
|
+// 点击保存
|
|
|
+const save = (record: Member) => {
|
|
|
+ delete state.editableData[record.user_id]
|
|
|
updateUserInfo(workspaceId, record.user_id, record).then(res => {
|
|
|
if (res.code !== 0) {
|
|
|
message.error(res.message)
|
|
|
@@ -163,13 +176,13 @@ function save(record: Member) {
|
|
|
}
|
|
|
|
|
|
// 点击搜索
|
|
|
-const onClickSearch = async () => {
|
|
|
- console.log('点击搜索');
|
|
|
+const onClickSearch = async (query: any) => {
|
|
|
+ await fetchList(query);
|
|
|
}
|
|
|
|
|
|
// 点击重置
|
|
|
-const onClickReset = async () => {
|
|
|
- console.log('点击重置');
|
|
|
+const onClickReset = async (query: any) => {
|
|
|
+ await fetchList(query);
|
|
|
}
|
|
|
</script>
|
|
|
|