index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <template>
  2. <div>
  3. <el-card class="content">
  4. <!-- 标题区域 -->
  5. <el-row class="card_title">账号管理</el-row>
  6. <!-- 筛选区域 -->
  7. <el-row :gutter="35" class="card_search">
  8. <el-col :span="5">
  9. 账号:
  10. <el-input
  11. style="width: 180px"
  12. placeholder="请输入账号"
  13. clearable
  14. v-model="searchAccount"
  15. ></el-input>
  16. </el-col>
  17. <el-col :span="5">
  18. 姓名:
  19. <el-input
  20. style="width: 180px"
  21. placeholder="请输入姓名"
  22. clearable
  23. v-model="searchName"
  24. ></el-input>
  25. </el-col>
  26. <el-col :span="5">
  27. 创建时间:
  28. <el-date-picker
  29. type="date"
  30. placeholder="请选择创建时间"
  31. value-format="YYYY-MM-DD"
  32. v-model="searchTime"
  33. />
  34. </el-col>
  35. <el-col :span="4">
  36. <el-button type="primary" @click="getData">
  37. <el-icon><Search /></el-icon>
  38. <span> 查询</span>
  39. </el-button>
  40. </el-col>
  41. </el-row>
  42. <!-- 新增账号按钮区域 -->
  43. <el-row class="card_button">
  44. <el-button type="primary" @click="handleAdd">
  45. <el-icon><Plus /></el-icon>
  46. <span> 新增账号</span>
  47. </el-button>
  48. </el-row>
  49. <!-- 表格区域 -->
  50. <el-table
  51. stripe
  52. height="481"
  53. :data="tableData"
  54. style="width: 100%"
  55. :header-cell-style="{ backgroundColor: '#F0F3F7' }"
  56. >
  57. <el-table-column type="index" width="55" align="center" label="序号" />
  58. <el-table-column
  59. width="200"
  60. align="center"
  61. prop="userName"
  62. label="账号"
  63. />
  64. <el-table-column
  65. width="200"
  66. align="center"
  67. show-overflow-tooltip
  68. prop="name"
  69. label="姓名"
  70. />
  71. <el-table-column show-overflow-tooltip align="center" label="角色">
  72. <template #default="{ row }">
  73. {{ row.adminType == 1 ? '超级管理员' : '管理员' }}
  74. </template>
  75. </el-table-column>
  76. <el-table-column align="center" prop="time" label="创建时间" />
  77. <el-table-column width="200" align="center" label="操作">
  78. <template #default="{ row }">
  79. <el-button type="success" plain @click="handleEdit(row)"
  80. >编辑
  81. </el-button>
  82. <el-button
  83. v-if="row.adminType == 2"
  84. type="danger"
  85. plain
  86. @click="handleDelete(row.id)"
  87. >删除
  88. </el-button>
  89. </template>
  90. </el-table-column>
  91. </el-table>
  92. <!-- 分页器区域 -->
  93. <el-row class="card_pagination">
  94. <el-pagination
  95. v-model:current-page="currentPage"
  96. v-model:page-size="pageSize"
  97. :page-sizes="[8, 20, 50, 100]"
  98. layout="total, sizes, prev, pager, next, jumper"
  99. :total="total"
  100. @size-change="handleSizeChange"
  101. @current-change="handleCurrentChange"
  102. />
  103. </el-row>
  104. </el-card>
  105. <!-- 编辑弹窗区域 -->
  106. <el-dialog
  107. v-model="dialogVisible"
  108. title="编辑账号"
  109. width="25%"
  110. top="20vh"
  111. :close-on-click-modal="false"
  112. >
  113. <div class="dialog_box">
  114. <div class="dialog_item">
  115. <span>账号:</span>
  116. <el-input
  117. style="width: 180px"
  118. placeholder="请输入账号"
  119. clearable
  120. v-model="editInfo.userName"
  121. ></el-input>
  122. </div>
  123. <div class="dialog_item">
  124. <span>姓名:</span>
  125. <el-input
  126. style="width: 180px"
  127. placeholder="请输入姓名"
  128. clearable
  129. v-model="editInfo.name"
  130. ></el-input>
  131. </div>
  132. <div class="dialog_item">
  133. <span>密码:</span>
  134. <el-input
  135. type="password"
  136. :show-password="true"
  137. style="width: 180px"
  138. placeholder="请输入密码"
  139. clearable
  140. v-model="editInfo.newPassword"
  141. ></el-input>
  142. </div>
  143. <div class="dialog_item">
  144. <span>确认密码:</span>
  145. <el-input
  146. type="password"
  147. :show-password="true"
  148. style="width: 180px"
  149. placeholder="请再次输入新密码"
  150. clearable
  151. v-model="editInfo.newPassword2"
  152. ></el-input>
  153. </div>
  154. </div>
  155. <template #footer>
  156. <span class="dialog-footer">
  157. <el-button @click="dialogVisible = false">取消</el-button>
  158. <el-button type="primary" @click="handleEditConfirm">
  159. 确定
  160. </el-button>
  161. </span>
  162. </template>
  163. </el-dialog>
  164. <!-- 新增账号弹窗区域 -->
  165. <el-dialog
  166. v-model="dialogVisibleAdd"
  167. title="新增账号"
  168. width="25%"
  169. top="20vh"
  170. :close-on-click-modal="false"
  171. >
  172. <div class="dialog_box">
  173. <div class="dialog_item">
  174. <span>账号:</span>
  175. <el-input
  176. style="width: 180px"
  177. placeholder="请输入账号"
  178. clearable
  179. v-model="addInfo.userName"
  180. ></el-input>
  181. </div>
  182. <div class="dialog_item">
  183. <span>姓名:</span>
  184. <el-input
  185. style="width: 180px"
  186. placeholder="请输入姓名"
  187. clearable
  188. v-model="addInfo.name"
  189. ></el-input>
  190. </div>
  191. <div class="dialog_item">
  192. <span>密码:</span>
  193. <el-input
  194. type="password"
  195. :show-password="true"
  196. style="width: 180px"
  197. placeholder="请输入密码"
  198. clearable
  199. v-model="addInfo.newPassword"
  200. ></el-input>
  201. </div>
  202. <div class="dialog_item">
  203. <span>确认密码:</span>
  204. <el-input
  205. type="password"
  206. :show-password="true"
  207. style="width: 180px"
  208. placeholder="请再次输入新密码"
  209. clearable
  210. v-model="addInfo.newPassword2"
  211. ></el-input>
  212. </div>
  213. </div>
  214. <template #footer>
  215. <span class="dialog-footer">
  216. <el-button @click="dialogVisibleAdd = false">取消</el-button>
  217. <el-button type="primary" @click="handleEditConfirmAdd">
  218. 确定
  219. </el-button>
  220. </span>
  221. </template>
  222. </el-dialog>
  223. </div>
  224. </template>
  225. <script setup>
  226. import { ref, onMounted } from 'vue'
  227. import { ElMessage, ElMessageBox } from 'element-plus'
  228. import {
  229. getUserList,
  230. editUserList,
  231. addUserList,
  232. deleteUserList
  233. } from '@/api/user'
  234. import { RSAencrypt } from '@/utils/jsencrypt'
  235. onMounted(() => {
  236. getData()
  237. })
  238. // 获取账号管理列表
  239. const getData = async () => {
  240. const res = await getUserList({
  241. userName: searchAccount.value,
  242. name: searchName.value,
  243. time: searchTime.value,
  244. currPage: currentPage.value,
  245. pageSize: pageSize.value
  246. })
  247. // console.log(res)
  248. tableData.value = res.list
  249. total.value = res.totalCount
  250. currentPage.value = res.currPage
  251. }
  252. // 筛选区域数据
  253. const searchAccount = ref('')
  254. const searchName = ref('')
  255. const searchTime = ref('')
  256. // 账号管理列表数据
  257. const tableData = ref([])
  258. // 编辑弹窗数据
  259. const editInfo = ref({
  260. userName: '',
  261. name: '',
  262. newPassword: '',
  263. newPassword2: ''
  264. })
  265. // 新增账号弹窗数据
  266. const addInfo = ref({
  267. userName: '',
  268. name: '',
  269. newPassword: '',
  270. newPassword2: ''
  271. })
  272. // 总条数
  273. const total = ref(0)
  274. // 当前页
  275. const currentPage = ref(1)
  276. // 每页多少条
  277. const pageSize = ref(8)
  278. // 编辑弹窗显示隐藏控制
  279. const dialogVisible = ref(false)
  280. // 新增账号弹窗显示隐藏控制
  281. const dialogVisibleAdd = ref(false)
  282. // 删除按钮回调
  283. const handleDelete = (id) => {
  284. ElMessageBox.confirm('确定删除吗?', '提示', {
  285. confirmButtonText: '确定',
  286. cancelButtonText: '取消',
  287. type: 'warning'
  288. })
  289. .then(async () => {
  290. const res = await deleteUserList({
  291. ids: [id]
  292. })
  293. // console.log(res)
  294. if (res == null) {
  295. ElMessage.success('删除成功')
  296. getData()
  297. }
  298. })
  299. .catch(() => {
  300. ElMessage.info('已取消')
  301. })
  302. }
  303. // 新增按钮回调
  304. const handleAdd = () => {
  305. dialogVisibleAdd.value = true
  306. addInfo.value = {
  307. userName: '',
  308. name: '',
  309. newPassword: '',
  310. newPassword2: ''
  311. }
  312. }
  313. // 每页条数改变时的回调
  314. const handleSizeChange = (val) => {
  315. pageSize.value = val
  316. }
  317. // 当前页改变时的回调
  318. const handleCurrentChange = (val) => {
  319. currentPage.value = val
  320. }
  321. // 编辑按钮回调
  322. const handleEdit = (row) => {
  323. dialogVisible.value = true
  324. editInfo.value = Object.assign(editInfo.value, row)
  325. }
  326. // 编辑弹窗确定按钮回调
  327. const handleEditConfirm = async () => {
  328. if (editInfo.value.newPassword === '') {
  329. ElMessage.error('请输入密码')
  330. return
  331. }
  332. if (editInfo.value.newPassword2 === '') {
  333. ElMessage.error('请输入确认新密码')
  334. return
  335. }
  336. if (editInfo.value.newPassword !== editInfo.value.newPassword2) {
  337. ElMessage.error('两次输入的密码不一致')
  338. return
  339. }
  340. const res = await editUserList({
  341. id: editInfo.value.id,
  342. userName: editInfo.value.userName,
  343. name: editInfo.value.name,
  344. password: RSAencrypt(editInfo.value.newPassword)
  345. })
  346. // console.log(res)
  347. if (res == null) {
  348. dialogVisible.value = false
  349. editInfo.value.newPassword = ''
  350. editInfo.value.newPassword2 = ''
  351. ElMessage.success('编辑账号成功')
  352. getData()
  353. }
  354. }
  355. // 新增账号弹窗确定按钮回调
  356. const handleEditConfirmAdd = async () => {
  357. if (addInfo.value.userName === '') {
  358. ElMessage.error('请输入账号')
  359. return
  360. }
  361. if (addInfo.value.name === '') {
  362. ElMessage.error('请输入姓名')
  363. return
  364. }
  365. if (addInfo.value.newPassword === '') {
  366. ElMessage.error('请输入密码')
  367. return
  368. }
  369. if (addInfo.value.newPassword2 === '') {
  370. ElMessage.error('请输入确认新密码')
  371. return
  372. }
  373. if (addInfo.value.newPassword !== addInfo.value.newPassword2) {
  374. ElMessage.error('两次输入的密码不一致')
  375. return
  376. }
  377. const res = await addUserList({
  378. userName: addInfo.value.userName,
  379. name: addInfo.value.name,
  380. password: RSAencrypt(addInfo.value.newPassword)
  381. })
  382. // console.log(res)
  383. if (res == null) {
  384. ElMessage.success('添加成功')
  385. dialogVisibleAdd.value = false
  386. getData()
  387. }
  388. }
  389. </script>
  390. <style lang="scss" scoped>
  391. .content {
  392. width: 1650px;
  393. height: 782px;
  394. ::v-deep .el-card__body {
  395. padding: 0 27px;
  396. }
  397. .card_title {
  398. line-height: 58px;
  399. font-size: 17px;
  400. font-weight: bold;
  401. border-bottom: 2px solid #d9d9d9;
  402. }
  403. .card_search {
  404. line-height: 85px;
  405. font-size: 13px;
  406. font-weight: bold;
  407. }
  408. .card_button {
  409. height: 53px;
  410. }
  411. .card_pagination {
  412. float: right;
  413. line-height: 96px;
  414. }
  415. }
  416. .dialog_box {
  417. height: 150px;
  418. .dialog_item {
  419. height: 30px;
  420. margin-bottom: 20px;
  421. span {
  422. display: inline-block;
  423. width: 70px;
  424. }
  425. }
  426. }
  427. ::v-deep .el-button--primary {
  428. background-color: #0061ff;
  429. }
  430. ::v-deep .el-dialog__header {
  431. margin: 0;
  432. font-weight: bold;
  433. background-color: #edf1f5;
  434. }
  435. ::v-deep
  436. .el-table--striped
  437. .el-table__body
  438. tr.el-table__row--striped.el-table__row--striped.el-table__row--striped
  439. td {
  440. background-color: #f0f3f7;
  441. }
  442. </style>