tj
2025-06-05 bba272999cc546f65781bf3d20245a3f819af67f
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<template>
  <div class="container">
    <div class="header">
      <div class="title">用户列表</div>
      <!-- 分组选择下拉框 -->
      <el-select filterable v-model="groupId" placeholder="请选择分组" @change="handleChange" clearable>
        <el-option v-for="(group, index) in allGroups" :key="index" :label="group.name" :value="group.id"> </el-option>
      </el-select>
    </div>
    <!-- 表格 -->
    <el-table :data="tableData" label-width="auto" v-loading="loading" @row-dblclick="rowDoubleClick">
      <el-table-column prop="nickname" label="姓名"></el-table-column>
      <el-table-column prop="username" label="用户名"></el-table-column>
      <el-table-column prop="email" label="邮箱"></el-table-column>
      <el-table-column prop="hiredate" label="入职日期"></el-table-column>
      <el-table-column prop="unhiredate" label="离职日期"></el-table-column>
      <el-table-column prop="staff_status" label="员工状态">
        <template #default="scope">
          <el-tag :type="scope.row.staff_status === 1 ? '' : 'success'" disable-transitions>
            <span v-if="scope.row.staff_status === 1">在职</span>
            <span v-if="scope.row.staff_status === 0">离职</span>
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="show_board_flag" label="展示看板">
        <template #default="scope">
          <el-tag :type="scope.row.show_board_flag === 1 ? '' : 'success'" disable-transitions>
            <span v-if="scope.row.show_board_flag === 1">展示</span>
            <span v-if="scope.row.show_board_flag === 0">不展示</span>
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="groupNames" label="所属分组"></el-table-column>
      <el-table-column label="操作" fixed="right" width="275">
        <template #default="scope">
          <el-button plain size="mini" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button plain size="mini" type="danger" @click="handleDelete(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="pagination">
      <el-pagination
        :total="totalNum"
        :background="true"
        :page-size="pageCount"
        v-if="refreshPagination"
        :current-page="currentPage"
        layout="prev, pager, next, jumper"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
    <!-- 弹窗 -->
    <el-dialog title="用户信息" :append-to-body="true" :before-close="handleClose" v-model="dialogFormVisible">
      <div style="margin-top: -25px">
        <el-tabs v-model="activeTab" @tab-click="handleClick">
          <el-tab-pane label="修改信息" name="修改信息">
            <user-info
              :id="id"
              ref="info"
              class="info"
              pageType="edit"
              :info="userInfo"
              :submit="false"
              :allGroups="allGroups"
              labelPosition="right"
              v-if="dialogFormVisible"
              @handleInfoResult="handleInfoResult"
            />
          </el-tab-pane>
          <el-tab-pane label="修改密码" name="修改密码">
            <user-password @handlePasswordResult="handlePasswordResult" ref="password" :id="id" class="password" />
          </el-tab-pane>
        </el-tabs>
      </div>
      <!-- 按键操作 -->
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="confirmEdit">确 定</el-button>
          <el-button @click="resetForm">重 置</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script>
import { ref, reactive } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'
import AdminModel from 'lin/model/admin'
 
import UserInfo from './user-info'
import UserPassword from './user-password'
import { useUserList, useFormData } from './use-user'
 
export default {
  components: { UserInfo, UserPassword },
  setup(props, ctx) {
    const info = ref(false)
    const password = ref(false)
    const dialogFormVisible = ref(false) // 弹窗遮罩层
    const refreshPagination = ref(true) // 页数增加的时候,因为缓存的缘故,需要刷新Pagination组件
 
    const { allGroups, loading, groupId, totalNum, tableData, pageCount, currentPage, getAdminUsers } = useUserList()
    const {
      id,
      activeTab,
      resetForm,
      confirmEdit,
      handleClose,
      handleClick,
      handleChange,
      handleInfoResult,
      handleCurrentChange,
      handlePasswordResult,
    } = useFormData(ctx, dialogFormVisible, getAdminUsers, currentPage, loading, info, password)
 
    const userInfo = reactive({
      email: '',
      username: '',
      password: '',
      groups: [],
      confirm_password: '',
 
      staff_status: '',
      show_board_flag: '',
      hiredate: '',
      unhiredate: '',
      send_email_flag: '',
    })
 
    /**
     * 修改管理员信息
     */
    const handleEdit = row => {
      id.value = row.id
      userInfo.email = row.email
      userInfo.groups = row.groups
      userInfo.username = row.username
      userInfo.nickname = row.nickname
 
      userInfo.staff_status = String(row.staff_status)
      userInfo.show_board_flag = String(row.show_board_flag)
      userInfo.hiredate = row.hiredate
      userInfo.unhiredate = row.unhiredate
      userInfo.send_email_flag = row.send_email_flag
 
      dialogFormVisible.value = true
    }
 
    /**
     * 删除管理员数据
     */
    const handleDelete = id => {
      let res
      ElMessageBox.confirm('此操作将永久删除该用户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          try {
            loading.value = true
            res = await AdminModel.deleteOneUser(id)
          } catch (e) {
            loading.value = false
            console.error(e)
          }
          if (res.code < window.MAX_SUCCESS_CODE) {
            loading.value = false
            if (totalNum.value % pageCount.value === 1 && currentPage.value !== 1) {
              // 判断删除的是不是每一页的最后一条数据
              currentPage.value--
            }
            await getAdminUsers()
            ElMessage.success(`${res.message}`)
          } else {
            loading.value = false
            ElMessage.error(`${res.message}`)
          }
        })
        .catch(() => {
          // 用户点击取消按钮时执行的操作
          // 可以选择不做任何事情,也可以显示取消消息
          // ElMessage.info('操作已取消'); // 如果需要显示取消消息,可以取消注释
        })
    }
 
    const rowDoubleClick = row => {
      handleEdit(row)
    }
 
    return {
      id,
      info,
      groupId,
      loading,
      password,
      userInfo,
      totalNum,
      allGroups,
      tableData,
      activeTab,
      resetForm,
      pageCount,
      handleEdit,
      confirmEdit,
      handleClose,
      currentPage,
      handleClick,
      handleChange,
      handleDelete,
      rowDoubleClick,
      handleInfoResult,
      refreshPagination,
      dialogFormVisible,
      handleCurrentChange,
      handlePasswordResult,
    }
  },
}
</script>
 
<style lang="scss" scoped>
.container {
  padding: 0 30px;
 
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
 
    .title {
      height: 59px;
      line-height: 59px;
      color: $parent-title-color;
      font-size: 16px;
      font-weight: 500;
    }
  }
 
  .pagination {
    display: flex;
    justify-content: flex-end;
    margin: 20px;
  }
}
 
.info {
  margin-left: -55px;
  margin-bottom: -30px;
}
 
.password {
  margin-top: 20px;
  margin-left: -55px;
  margin-bottom: -20px;
}
</style>