zhuanghaoguanli.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-col :span="24" class="first-row">
  5. <div class="tag">账号管理</div>
  6. </el-col>
  7. </el-row>
  8. <el-row>
  9. <el-col :span="24" class="second-row">
  10. <!-- <el-form :inline="true" class="demo-form-inline">
  11. <el-form-item label="账号:" class="shuibiaoId">
  12. <el-input v-model="account" placeholder="请输入账号" clearable maxlength="16"></el-input>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" @click="onSearch">查找</el-button>
  16. </el-form-item>
  17. </el-form> -->
  18. <div class="btn-add">
  19. <el-button type="primary" icon="el-icon-add" @click="handleAdd">添加</el-button>
  20. </div>
  21. </el-col>
  22. </el-row>
  23. <hr style="background-color: #CCCCCC;height: 1px;border: 0;">
  24. <el-row>
  25. <el-col :span="24" class="third-row">
  26. <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
  27. highlight-current-row>
  28. <!-- <el-table-column label="昵称" align="center">
  29. <template slot-scope="scope">{{ scope.row.name }}</template>
  30. </el-table-column> -->
  31. <el-table-column prop="userName" label="账号" align="center"></el-table-column>
  32. <el-table-column prop="adminType" label="类别" align="center" :formatter="adminType">
  33. </el-table-column>
  34. <el-table-column prop="status" label="状态" show-overflow-tooltip :formatter="formatStatus">
  35. </el-table-column>
  36. <el-table-column label="操作" align="center" width="80">
  37. <el-button type="text" class="del-btn" slot-scope="scope" v-if="myUserType === '0'"
  38. @click="handleDelete(scope.$index, scope.row)">删除
  39. </el-button>
  40. </el-table-column>
  41. <el-table-column width="130">
  42. <el-button type="text" slot-scope="scope" v-if="myUserType === '0'"
  43. @click="handleEdit(scope.$index, scope.row)">编辑
  44. </el-button>
  45. </el-table-column>
  46. </el-table>
  47. <div style="margin-top: 20px" class="table-footer">
  48. <div class="pages">
  49. <el-pagination layout="prev, pager, next" :total="total_rows" :current-page.sync="current_page"
  50. :hide-on-single-page="true" :page-size="page_rows" @current-change="handleCurrentChange">
  51. </el-pagination>
  52. </div>
  53. </div>
  54. </el-col>
  55. </el-row>
  56. <el-row>
  57. <el-col :span="24" class="forth-row">
  58. <!-- 添加对话框 -->
  59. <el-dialog title="添加账号" :visible.sync="adddialogFormVisible" width="500px" top="0vh" class="my-dialog"
  60. :close-on-click-modal="false" :close-on-press-escape="false">
  61. <hr
  62. style="width: 100%; position: absolute; top: 60px; left: 0px;background-color: #CCCCCC;height: 1px;border: 0;">
  63. <el-form :model="addform" :rules="addRules" ref="addform">
  64. <el-form-item label="账号:" prop="userName" :label-width="formLabelWidth">
  65. <el-input v-model="addform.userName" autocomplete="off" minlength="5" maxlength="16">
  66. </el-input>
  67. </el-form-item>
  68. <el-form-item label="密码:" prop="password" :label-width="formLabelWidth">
  69. <el-input v-model="addform.password" type="password" minlength="5" autocomplete="off"
  70. maxlength="16">
  71. </el-input>
  72. </el-form-item>
  73. <el-form-item label="确认密码:" prop="comfirmPass" :label-width="formLabelWidth">
  74. <el-input v-model="addform.comfirmPass" type="password" minlength="5" autocomplete="off"
  75. maxlength="16">
  76. </el-input>
  77. </el-form-item>
  78. <el-form-item label="类别:" prop="adminType" :label-width="formLabelWidth">
  79. <el-radio v-model="addform.adminType" label="1">管理员</el-radio>
  80. <el-radio v-model="addform.adminType" label="0">超级管理员</el-radio>
  81. </el-form-item>
  82. <el-form-item label="状态:" prop="status" :label-width="formLabelWidth">
  83. <el-radio v-model="addform.status" label="1">正常</el-radio>
  84. <el-radio v-model="addform.status" label="0">冻结</el-radio>
  85. </el-form-item>
  86. </el-form>
  87. <div slot="footer" class="dialog-footer">
  88. <el-button @click="adddialogFormVisible = false">取 消</el-button>
  89. <el-button type="primary" @click="handleAddRow('addform')">确 定</el-button>
  90. </div>
  91. </el-dialog>
  92. <!-- 编辑对话框 -->
  93. <el-dialog title="编辑" :visible.sync="editdialogFormVisible" width="500px" top="0vh" class="my-dialog"
  94. :close-on-click-modal="false" :close-on-press-escape="false">
  95. <hr
  96. style="width: 100%; position: absolute; top: 60px; left: 0px;background-color: #CCCCCC;height: 1px;border: 0;">
  97. <el-form :model="form" :rules="formRules" ref="form">
  98. <el-form-item label="账号:" prop="userName" :label-width="formLabelWidth">
  99. <el-input ref="zhanghao" v-model="form.userName" autocomplete="off" maxlength="16">
  100. </el-input>
  101. </el-form-item>
  102. <!-- <el-form-item label="原密码:" prop="oldPassword" :label-width="formLabelWidth">
  103. <el-input ref="yuanmima" v-model="form.oldPassword" type="password" autocomplete="off"
  104. maxlength="16">
  105. </el-input>
  106. </el-form-item> -->
  107. <el-form-item label="新密码:" prop="password" :label-width="formLabelWidth">
  108. <el-input ref="xinmima" v-model="form.password" autocomplete="off" type="password"
  109. maxlength="16">
  110. </el-input>
  111. </el-form-item>
  112. <el-form-item label="确认新密码:" prop="comfirmPass" :label-width="formLabelWidth">
  113. <el-input ref="querenmima" v-model="form.comfirmPass" autocomplete="off" type="password"
  114. maxlength="16">
  115. </el-input>
  116. </el-form-item>
  117. <el-form-item label="类别" prop="adminType" :label-width="formLabelWidth">
  118. <el-radio v-model="form.adminType" label="1">管理员</el-radio>
  119. <el-radio v-model="form.adminType" label="0">超级管理员</el-radio>
  120. </el-form-item>
  121. <el-form-item label="状态:" prop="status" :label-width="formLabelWidth">
  122. <el-radio v-model="form.status" label="1">正常</el-radio>
  123. <el-radio v-model="form.status" label="0">冻结</el-radio>
  124. </el-form-item>
  125. </el-form>
  126. <div slot="footer" class="dialog-footer">
  127. <el-button @click="editdialogFormVisible = false">取 消</el-button>
  128. <el-button type="primary" @click="handleEditRow('form')">确 定</el-button>
  129. </div>
  130. </el-dialog>
  131. <!-- 删除对话框 -->
  132. <el-dialog :visible.sync="delDialogVisible" width="500px" center top="0vh" class="my-dialog"
  133. :close-on-click-modal="false" :close-on-press-escape="false">
  134. <div class="box-icon"></div>
  135. <span class="del-msg">确定删除【{{del_account}}】账号吗?</span>
  136. <span slot="footer" class="dialog-footer">
  137. <el-button @click="delDialogVisible = false">取 消</el-button>
  138. <el-button type="primary" @click="getDelPwd">确 定</el-button>
  139. <!-- <el-button type="primary" @click="handleDelRow">确 定</el-button> -->
  140. </span>
  141. </el-dialog>
  142. <!-- 删除账号密码验证对话框 -->
  143. <!-- <el-dialog title="验证密码" :visible.sync="delDialogEnterPwdVisible" width="500px" top="0vh"
  144. class="my-dialog" :close-on-click-modal="false" :close-on-press-escape="false">
  145. <hr
  146. style="width: 100%; position: absolute; top: 60px; left: 0px;background-color: #CCCCCC;height: 1px;border: 0;">
  147. <el-form :model="delConfirmPwdform" :rules="delConfirmPwdRules" ref="delConfirmPwdform">
  148. <el-form-item label="请输入密码:" prop="delPwd" :label-width="formLabelWidth">
  149. <el-input ref="delPwd" v-model="delConfirmPwdform.delPwd" type="password" autocomplete="off"
  150. maxlength="16">
  151. </el-input>
  152. </el-form-item>
  153. </el-form>
  154. <div slot="footer" class="dialog-footer">
  155. <el-button @click="delDialogEnterPwdVisible = false">取 消</el-button>
  156. <el-button type="primary" @click="getDelPwd('delConfirmPwdform')">确 定</el-button>
  157. </div>
  158. </el-dialog> -->
  159. </el-col>
  160. </el-row>
  161. </div>
  162. </template>
  163. <script>
  164. export default {
  165. data() {
  166. return {
  167. myUserType: '',
  168. addform: { // 添加框的数据绑定
  169. userName: '',
  170. password: '',
  171. comfirmPass: '',
  172. adminType: '1',
  173. status: '1',
  174. },
  175. addRules: {
  176. userName: [{
  177. required: true,
  178. message: '请输入账号',
  179. trigger: 'blur'
  180. },
  181. {
  182. min: 5,
  183. max: 16,
  184. message: '账号长度不小于5位',
  185. trigger: 'blur'
  186. }
  187. ],
  188. password: [{
  189. required: true,
  190. message: '请输入密码',
  191. trigger: 'blur'
  192. },
  193. {
  194. min: 5,
  195. max: 16,
  196. message: '密码长度不小于5位',
  197. trigger: 'blur'
  198. }
  199. ],
  200. comfirmPass: [{
  201. required: true,
  202. message: '请输入确认密码',
  203. trigger: 'blur'
  204. },
  205. {
  206. min: 5,
  207. max: 16,
  208. message: '确认密码长度不小于5位',
  209. trigger: 'blur'
  210. }
  211. ]
  212. },
  213. form: { // 编辑框的数据绑定
  214. id: 0,
  215. userName: '',
  216. adminType: '1',
  217. status: '1',
  218. // oldPassword: '',
  219. password: '',
  220. comfirmPass: ''
  221. },
  222. formRules: {
  223. name: [{
  224. required: true,
  225. message: '请输入昵称',
  226. trigger: 'blur'
  227. },
  228. {
  229. min: 5,
  230. max: 16,
  231. message: '昵称长度不小于5位',
  232. trigger: 'blur'
  233. }
  234. ],
  235. number: [{
  236. required: true,
  237. message: '请输入账号',
  238. trigger: 'blur'
  239. },
  240. {
  241. min: 5,
  242. max: 16,
  243. message: '账号长度不小于5位',
  244. trigger: 'blur'
  245. }
  246. ],
  247. // oldPassword: [{
  248. // required: true,
  249. // message: '请输入原密码',
  250. // trigger: 'blur'
  251. // },
  252. // {
  253. // min: 5,
  254. // max: 16,
  255. // message: '原密码长度不小于5位',
  256. // trigger: 'blur'
  257. // }
  258. // ],
  259. password: [{
  260. required: true,
  261. message: '请输入新密码',
  262. trigger: 'blur'
  263. },
  264. {
  265. min: 5,
  266. max: 16,
  267. message: '新密码长度不小于5位',
  268. trigger: 'blur'
  269. }
  270. ],
  271. comfirmPass: [{
  272. required: true,
  273. message: '请输入确认新密码',
  274. trigger: 'blur'
  275. },
  276. {
  277. min: 5,
  278. max: 16,
  279. message: '确认新密码长度不小于5位',
  280. trigger: 'blur'
  281. }
  282. ]
  283. },
  284. delConfirmPwdform: {
  285. delPwd: '' // 被删除的账号的密码
  286. },
  287. // delConfirmPwdRules: {
  288. // delPwd: [{
  289. // required: true,
  290. // message: '请输入密码进行验证',
  291. // trigger: 'blur'
  292. // },
  293. // {
  294. // min: 5,
  295. // max: 16,
  296. // message: '密码长度不小于5位',
  297. // trigger: 'blur'
  298. // }
  299. // ]
  300. // },
  301. del_id: 0, // 被删除的id
  302. del_account: '', // 被删除的账号
  303. account: '', // 需要查找的账号
  304. login_account: '', // 登陆的账号
  305. adddialogFormVisible: false, // 控制添加对话框显示、隐藏
  306. editdialogFormVisible: false, // 控制编辑对话框显示、隐藏
  307. delDialogEnterPwdVisible: false, // 控制删除账号时输入密码对话框
  308. delDialogVisible: false, // 控制删除对话框显示、隐藏
  309. formLabelWidth: '146px', // label宽度
  310. tableData: [], // 表格数据
  311. current_page: 1, // 当前所在页码
  312. page_rows: 8, // 每页显示的记录数
  313. total_rows: 0, // 总记录数
  314. token: ''
  315. }
  316. },
  317. created() {
  318. this.login_account = sessionStorage.getItem('uname')
  319. this.token = sessionStorage.getItem('token')
  320. this.myUserType = sessionStorage.getItem('userType')
  321. // 获取账号列表
  322. this.updateTable()
  323. },
  324. methods: {
  325. adminType(e) {
  326. if (e.adminType === '1') {
  327. return '管理员'
  328. } else if (e.adminType === '0') {
  329. return '超级管理员'
  330. }
  331. return '普通用户'
  332. },
  333. formatStatus(e) {
  334. if (e.status === '1') {
  335. return '正常'
  336. } else if (e.status === '0') {
  337. return '冻结'
  338. }
  339. return '未知'
  340. },
  341. /**
  342. * 改变页码
  343. * @param {Object} val
  344. */
  345. handleCurrentChange(val) {
  346. this.current_page = val
  347. // 查询账号相关信息
  348. this.updateTable()
  349. },
  350. /**
  351. * 管理员列表,填充表格变量
  352. */
  353. updateTable() {
  354. var _this = this
  355. _this.tableData = []
  356. let params = {
  357. curPage: this.current_page,
  358. pageSize: this.page_rows,
  359. orderField: this.login_account
  360. }
  361. // if (this.account) {
  362. // params.userName = this.account
  363. // }
  364. // _this.rows_total = 0
  365. this.$axios({
  366. method: "get",
  367. url: "/diseaseRight/adminInfo/list",
  368. headers: {
  369. 'Content-type': 'application/x-www-form-urlencoded;charset=utf-8'
  370. },
  371. data: params
  372. })
  373. .then(res => {
  374. console.log(res.data);
  375. if (res.data.success) {
  376. _this.tableData = res.data.data.list
  377. _this.total_rows = res.data.data.totalCount
  378. var i = 0
  379. for (; i < _this.tableData.length; i++) {
  380. if (_this.tableData[i].userName == _this.login_account) {
  381. sessionStorage.setItem('unic', _this.tableData[i].userName)
  382. break
  383. }
  384. }
  385. // _this.$emit('sonFun', _this.tableData[i].userName)
  386. } else {
  387. _this.$message.success('【获取账号】暂无数据!');
  388. }
  389. })
  390. .catch(err => {
  391. // console.log(err);
  392. _this.$message.error('【获取账号】请求异常: ' + err);
  393. })
  394. },
  395. /**
  396. * 查找账号
  397. */
  398. onSearch() {
  399. // if (!this.account) {
  400. // this.$message.error('请输入账号')
  401. // return
  402. // }
  403. // 查询账号相关信息
  404. this.updateTable()
  405. },
  406. /**
  407. * 添加账号
  408. */
  409. handleAdd() {
  410. this.adddialogFormVisible = true
  411. },
  412. /**
  413. * 添加一条账号
  414. */
  415. handleAddRow(formName) {
  416. this.$refs[formName].validate((valid) => {
  417. if (valid) {
  418. if (!String(this.addform.userName).trim()) {
  419. this.$message.error('请输入账号')
  420. return
  421. }
  422. if (!String(this.addform.password).trim()) {
  423. this.$message.error('请输入密码')
  424. return
  425. }
  426. if (!String(this.addform.comfirmPass).trim()) {
  427. this.$message.error('请输入确认密码')
  428. return
  429. }
  430. if (String(this.addform.password).trim() != String(this.addform.comfirmPass).trim()) {
  431. this.$message.error('密码与确认密码不一致!')
  432. return
  433. }
  434. var params = {
  435. userName: String(this.addform.userName).trim(),
  436. password: String(this.addform.password).trim(),
  437. adminType: String(this.addform.adminType).trim(),
  438. status: String(this.addform.status).trim()
  439. }
  440. var _this = this
  441. this.$axios({
  442. method: "post",
  443. url: "/diseaseRight/adminInfo/save",
  444. headers: {
  445. 'Admin-Token': this.token,
  446. 'Content-type': 'application/json; charset=utf-8'
  447. },
  448. data: params
  449. })
  450. .then(res => {
  451. // console.log(res.data);
  452. if (res.data.success) {
  453. this.adddialogFormVisible = false
  454. _this.$message.success('【账号添加】成功!');
  455. _this.addform = {
  456. userName: '',
  457. password: '',
  458. comfirmPass: '',
  459. adminType: '1',
  460. status: '1',
  461. }
  462. // 更新列表
  463. this.updateTable()
  464. } else if (res.data.message === "数据已存在") {
  465. _this.$message.error('账号已存在');
  466. } else {
  467. _this.$message.error(res.data.message);
  468. }
  469. })
  470. .catch(err => {
  471. // console.log(err);
  472. _this.$message.error('【账号】添加请求异常: ' + err);
  473. })
  474. } else {
  475. // this.$message.error('表单验证失败!')
  476. return false;
  477. }
  478. });
  479. },
  480. /**
  481. * 编辑对话框
  482. * @param {Object} index
  483. * @param {Object} row
  484. */
  485. handleEdit(index, row) {
  486. console.log(index, row);
  487. this.editdialogFormVisible = true
  488. this.form.id = row.id
  489. this.form.userName = row.userName
  490. this.form.adminType = row.adminType
  491. this.form.status = row.status
  492. // this.form.oldPassword = ''
  493. this.form.password = ''
  494. this.form.comfirmPass = ''
  495. },
  496. /**
  497. * 编辑更新指定的id所在的行
  498. */
  499. handleEditRow(formName) {
  500. var _this = this
  501. _this.$refs[formName].validate((valid) => {
  502. if (valid) {
  503. if (!String(_this.form.userName).trim()) {
  504. _this.$message.error('请输入账号')
  505. _this.$refs['nicheng'].focus()
  506. return
  507. }
  508. // if (!String(_this.form.oldPassword).trim()) {
  509. // _this.$message.error('请输入原密码')
  510. // _this.$refs['yuanmima'].focus()
  511. // return
  512. // }
  513. if (!String(_this.form.password).trim()) {
  514. _this.$message.error('请输入新密码')
  515. _this.$refs['xinmima'].focus()
  516. return
  517. }
  518. if (String(_this.form.password).trim() != String(_this.form.comfirmPass).trim()) {
  519. _this.$message.error('新密码和确认新密码不一致!')
  520. _this.$refs['querenmima'].focus()
  521. return
  522. }
  523. if (!String(_this.form.adminType).trim()) {
  524. _this.$message.error('请输入类别')
  525. _this.$refs['zhanghao'].focus()
  526. return
  527. }
  528. if (!String(_this.form.status).trim()) {
  529. _this.$message.error('请输入状态')
  530. _this.$refs['zhanghao'].focus()
  531. return
  532. }
  533. let params = {
  534. id: _this.form.id,
  535. userName: String(_this.form.userName).trim(),
  536. adminType: String(_this.form.adminType).trim(),
  537. // oldpass: String(_this.form.oldPassword).trim(),
  538. password: String(_this.form.password).trim(),
  539. status: String(_this.form.status).trim()
  540. }
  541. _this.$axios({
  542. method: "put",
  543. url: "/diseaseRight/adminInfo/update",
  544. headers: {
  545. 'Admin-Token': this.token,
  546. 'Content-type': 'application/json; charset=utf-8'
  547. },
  548. data: params
  549. })
  550. .then(res => {
  551. console.log(res.data);
  552. if (res.data.success) {
  553. _this.editdialogFormVisible = false
  554. _this.$message.success('【账号】修改成功!');
  555. // 更新表格
  556. _this.updateTable()
  557. _this.form = {
  558. id: 0,
  559. userName: '',
  560. adminType: '1',
  561. status: '1',
  562. // oldPassword: '',
  563. password: '',
  564. comfirmPass: ''
  565. }
  566. } else {
  567. _this.$message.error('【账号】修改失败!' + res.data.msg);
  568. }
  569. })
  570. .catch(err => {
  571. // console.log(err);
  572. _this.$message.error('【账号】修改请求异常: ' + err);
  573. })
  574. } else {
  575. // _this.$message.error('表单验证失败!')
  576. return false;
  577. }
  578. });
  579. },
  580. /**
  581. * 删除对话框
  582. * @param {Object} index
  583. * @param {Object} row
  584. */
  585. handleDelete(index, row) {
  586. this.delDialogVisible = true
  587. this.del_account = row.userName
  588. this.del_id = row.id
  589. },
  590. /**
  591. * 被删除账号的密码
  592. */
  593. getDelPwd(formName) {
  594. var _this = this
  595. // var params = {
  596. // id: _this.del_id
  597. // }
  598. _this.$axios({
  599. method: "delete",
  600. url: "/diseaseRight/adminInfo/delete/" + _this.del_id,
  601. headers: {
  602. 'Admin-Token': this.token,
  603. 'Content-type': 'application/x-www-form-urlencoded;charset=utf-8'
  604. },
  605. // data: params
  606. })
  607. .then(res => {
  608. // console.log(res.data);
  609. if (res.data.success) {
  610. _this.$message.success('账号【' + this.del_account + '】删除成功!');
  611. _this.delDialogVisible = false
  612. _this.updateTable()
  613. } else {
  614. _this.$message.error('账号【' + this.del_account + '】删除失败!');
  615. }
  616. })
  617. .catch(err => {
  618. // console.log(err);
  619. _this.$message.error('账号【' + this.del_account + '】删除请求异常: ' + err);
  620. })
  621. },
  622. /**
  623. * 删除指定的id所在的行
  624. */
  625. // handleDelRow() {
  626. // if (this.login_account == this.del_account) {
  627. // this.delDialogVisible = false
  628. // this.$message.error('不能删除当前登录账号!')
  629. // return
  630. // }
  631. // this.delConfirmPwdform.delPwd = ''
  632. // this.delDialogEnterPwdVisible = true
  633. // setTimeout(() => {
  634. // this.$refs['delPwd'].focus()
  635. // }, 200)
  636. // }
  637. }
  638. }
  639. </script>
  640. <style scoped>
  641. @import url("zhuanghaoguanli.css");
  642. </style>