husq
2023-09-27 2c2bc8614c8ea0ce386369eb4924da1e6aa052d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
 
<template>
  <div class="table flex-display flex-column">
    <a-table :columns="columns" :data-source="data.member" :pagination="paginationProp" @change="refreshData" row-key="user_id"
    :row-selection="rowSelection" :rowClassName="(record, index) => ((index % 2) === 0 ? 'table-striped' : null)" :scroll="{ x: '100%', y: 600 }">
      <template v-for="col in ['organization_name', 'user_role', ]" #[col]="{ text, record }" :key="col">
        <div v-if="col == 'organization_name'">
          <a-input
            v-if="editableData[record.user_id]"
            v-model:value="editableData[record.user_id][col]"
            style="margin: -5px 0"
          />
          <template v-else>
            {{ text }}
          </template>
        </div>
        <!-- <div v-else-if="col == 'user_role'"> -->
          <!--  -->
        <!-- </div> -->
      </template>
      <template #action="{ record }">
        <div class="editable-row-operations">
          <span v-if="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;"><CloseOutlined /></span>
            </a-tooltip>
          </span>
          <span v-else class="fz18 flex-align-center flex-justify-between flex-row" style="color: #2d8cf0">
            <EditOutlined @click="edit(record)" />
            <DeleteOutlined @click="del(record)" />
          </span>
        </div>
      </template>
 
    </a-table>
  </div>
</template>
<script lang="ts" setup>
import { message, PaginationProps } from 'ant-design-vue'
import { TableState } from 'ant-design-vue/lib/table/interface'
import { onMounted, reactive, Ref, ref, UnwrapRef } from 'vue'
import { IPage } from '/@/api/http/type'
import { getAllUsersInfo, getUserPage, updateUserInfo } from '/@/api/manage'
import { ELocalStorageKey } from '/@/types'
import { EditOutlined, DeleteOutlined, CheckOutlined, CloseOutlined } from '@ant-design/icons-vue'
import { useMyStore } from '/@/store'
 
export interface Member {
    user_id: string
    username: string
    organization_name: string
    workspace_name: string
    project: string
    create_time: string
    user_role: string
    join_way: string
}
 
interface MemberData {
  member: Member[]
}
const columns = [
  { title: '账号', dataIndex: 'username', width: 150, sorter: (a: Member, b: Member) => a.username.localeCompare(b.username), className: 'titleStyle' },
  { title: '人员组织名称', dataIndex: 'deptName', sorter: (a: Member, b: Member) => a.organization_name.localeCompare(b.organization_name), width: 150, className: 'titleStyle' },
  { title: '用户角色', dataIndex: 'roleName', width: 150, className: 'titleStyle', slots: { customRender: 'user_role' } },
  { title: '所属项目', dataIndex: 'projectName', width: 150, className: 'titleStyle' },
  { title: '加入方式', dataIndex: 'join_way', width: 150, className: 'titleStyle', slots: { customRender: 'join_way' } },
  { title: '加入时间', dataIndex: 'createTime', width: 150, sorter: (a: Member, b: Member) => a.create_time.localeCompare(b.create_time), className: 'titleStyle' },
  { title: '操作', dataIndex: 'action', width: 70, className: 'titleStyle', slots: { customRender: 'action' } },
]
 
const data = reactive<MemberData>({
  member: []
})
 
const editableData: UnwrapRef<Record<string, Member>> = reactive({})
 
const paginationProp = reactive({
  pageSizeOptions: ['20', '50', '100'],
  showQuickJumper: true,
  showSizeChanger: true,
  pageSize: 50,
  current: 1,
  total: 0
})
 
const rowSelection = {
  onChange: (selectedRowKeys: (string | number)[], selectedRows: []) => {
    console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
  },
  onSelect: (record: any, selected: boolean, selectedRows: []) => {
    console.log(record, selected, selectedRows)
  },
  onSelectAll: (selected: boolean, selectedRows: [], changeRows: []) => {
    console.log(selected, selectedRows, changeRows)
  },
}
type Pagination = TableState['pagination']
 
const body: IPage = {
  page: 1,
  total: 0,
  page_size: 50
}
const workspaceId: string = localStorage.getItem(ELocalStorageKey.WorkspaceId)!
const store = useMyStore()
 
onMounted(() => {
  getAllUsers(workspaceId, body)
})
 
function refreshData (page: Pagination) {
  body.page = page?.current!
  body.page_size = page?.pageSize!
  getAllUsers(workspaceId, body)
}
 
function getAllUsers (workspaceId: string, page: IPage) {
  getAllUsersInfo(workspaceId, page).then(res => {
    const userList: Member[] = res.data.list
    data.member = userList
    paginationProp.total = res.data.pagination.total
    paginationProp.current = res.data.pagination.page
  })
}
 
function edit (record: Member) {
  editableData[record.user_id] = record
}
 
const del = (record: Member) => {
  console.log(record)
}
 
function save (record: Member) {
  delete editableData[record.user_id]
  updateUserInfo(workspaceId, record.user_id, record).then(res => {
    if (res.code !== 0) {
      message.error(res.message)
    }
  })
}
 
</script>
<style>
 
.table {
    background-color: white;
    margin: 20px;
    padding: 20px;
    height: 88vh;
}
.table-striped {
  background-color: #f7f9fa;
}
.ant-table {
  border-top: 1px solid rgb(0,0,0,0.06);
  border-bottom: 1px solid rgb(0,0,0,0.06);
}
.ant-table-tbody tr td {
  border: 0;
}
.ant-table td {
  white-space: nowrap;
}
.ant-table-thead tr th {
  background: white !important;
  border: 0;
}
th.ant-table-selection-column {
  background-color: white !important;
}
.ant-table-header {
  background-color: white !important;
}
</style>