accountHome.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <template>
  2. <div class="account-home">
  3. <div class="account-header">
  4. <div class="status flex-wrap">
  5. <div class="manageTitle">账号管理</div>
  6. <div class="status1"><span class="icon" />在线</div>
  7. <div class="status2"><span class="icon" />离线</div>
  8. <div class="status3"><span class="icon" />禁用</div>
  9. </div>
  10. <Search :is-slot="true" :is-title="false" @getSearchData="getSearchData" @clearSearchData="clearSearchData">
  11. <el-button class="btnAdd" @click="addAccount">新增</el-button>
  12. </Search>
  13. </div>
  14. <div class="content-box scrollbar">
  15. <template v-if="accountArr.length">
  16. <el-row v-infinite-scroll="load" :infinite-scroll-disabled="disabled" :infinite-scroll-distance="20" :gutter="24">
  17. <el-col v-for="(account,index) in accountArr" :key="index" :xs="24" :sm="12" :md="8" :lg="4" class="account-box">
  18. <div class="account-box-wrap">
  19. <div :class="account.user_status == 1 ? 'headOnline' : account.user_status == 2 ? 'headOffline' : 'headDisabled'" />
  20. <div>
  21. <div class="nameBox flex">
  22. <div class="flex-wrap">
  23. <div class="name">{{ account.user_name }}</div>
  24. <div class="loger" @click="toEdit(account.user_id)" />
  25. <div @click="authAccount(account)" class="loger cap-auth"></div>
  26. </div>
  27. <div class="del" @click="deleteUser(account)">
  28. <i class="el-icon-close" />
  29. </div>
  30. </div>
  31. <!-- <el-row>
  32. <el-col :span="24">{{ account.group }}</el-col>
  33. </el-row>
  34. <el-row class="content">
  35. <el-col :span="12">登录次数:<span>{{ account.LoginCount }}</span></el-col>
  36. <el-col :span="12" class="flexLeft">异常登录:<span>{{ account.ExceptionCount }}</span></el-col>
  37. </el-row> -->
  38. <el-row class="content">
  39. <el-col :span="24">权限项数:<span>{{ account.AuthCount }}</span></el-col>
  40. </el-row>
  41. <el-row class="content">
  42. <el-col :span="12">
  43. 状态:<span v-if="account.user_status == 1 || account.user_status == 2" class="used">启用</span>
  44. <span v-else class="unUsed">停用</span>
  45. </el-col>
  46. <el-col v-is="['userlist_btn_status_change','admin']" :span="12" class="flexLeft">
  47. <el-switch v-model="account.Flag" :active-value="true" :inactive-value="false" active-color="#2D67E3" inactive-color="#CFD6E2" @change="userActiveToggle(account)" />
  48. </el-col>
  49. </el-row>
  50. </div>
  51. </div>
  52. </el-col>
  53. </el-row>
  54. <template v-if="pages > 1">
  55. <p v-if="loading" class="center">加载中...</p>
  56. <p v-if="noMore" class="center">没有更多数据了~</p>
  57. </template>
  58. </template>
  59. <template v-else>
  60. <NoData />
  61. </template>
  62. </div>
  63. <Dialog :flag="dialogVisible">
  64. <div class="del-dialog">
  65. <div class="title del-title">删除账号</div>
  66. <div class="content del-content"><i class="el-icon-error error r10" />你确定要删除<span class="error l10">{{ deleteUserName }}</span>?</div>
  67. <div class="foot Delfoot right t30">
  68. <el-button size="medium" type="danger" class="r24" @click="del()">删除</el-button>
  69. <el-button size="medium" @click="dialogVisible = false">取消</el-button>
  70. </div>
  71. </div>
  72. </Dialog>
  73. <!--新增/编辑-->
  74. <Dialog :flag="editDialogVisible" width="508px" :show-flag="true">
  75. <div class="airportInfoDialog dialog-public-background">
  76. <div class="title">{{ editDialogTitle }}</div>
  77. <div class="content">
  78. <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="130px" class="demo-ruleForm">
  79. <el-form-item label="账号名称" prop="user_name">
  80. <el-input v-model="ruleForm.user_name" size="medium" placeholder="请输入账号名称" />
  81. </el-form-item>
  82. <el-form-item label="账号密码" prop="user_pwd">
  83. <el-input v-model="ruleForm.user_pwd" show-password class="r25" size="medium" placeholder="请输入密码" />
  84. <!-- <div class="flex-wrap">
  85. <el-input v-model="ruleForm.PassWord" class="r25" size="medium" placeholder="请输入密码" />
  86. <el-button size="medium" @click="resetPwd" style="position: relative;top: 4px;" class="r26" type="primary">重置密码</el-button>
  87. </div> -->
  88. </el-form-item>
  89. <el-form-item label="账号描述" prop="user_comment">
  90. <el-input v-model="ruleForm.user_comment" size="medium" type="textarea" :rows="3" placeholder="请输入角色描述" />
  91. </el-form-item>
  92. <el-form-item label="是否启用" prop="user_status">
  93. <el-radio v-model="ruleForm.user_status" :label="1">是</el-radio>
  94. <el-radio v-model="ruleForm.user_status" :label="2">否</el-radio>
  95. </el-form-item>
  96. </el-form>
  97. </div>
  98. <div class="foot center t30">
  99. <el-button size="medium" type="primary" class="r25 r26" @click="submitClickHandler()">提交</el-button>
  100. <el-button size="medium" class="r26" @click="resetForm('ruleForm')">取消</el-button>
  101. </div>
  102. </div>
  103. </Dialog>
  104. </div>
  105. </template>
  106. <script>
  107. import Search from '@/layout/components/Search'
  108. import Dialog from '@/layout/components/Dialog'
  109. import NoData from '@/components/nodata'
  110. import { GetAccountList, ChangeUserStatus, delAccount, getAccountDetails, editAccount, addAccount } from '@/api/Account'
  111. import { pwdProduce } from '@/utils/validate'
  112. import { mapGetters } from 'vuex'
  113. import { GeneralDataReception, Query } from '@/api/dataIntegration'
  114. import MD5 from 'blueimp-md5'
  115. export default {
  116. components: { Search, Dialog, NoData },
  117. data () {
  118. return {
  119. pwdStruc: '',
  120. pwdLengthBegin: 0,
  121. pwdLengthEnd: 0,
  122. dialogVisible: false,
  123. accountArr: [],
  124. deleteUserId: '',
  125. deleteUserName: '',
  126. userId: '',
  127. GroupId: '',
  128. GroupUpid: '',
  129. searchInfo: '', // 搜索内容
  130. PageIndex: 1,
  131. PageSize: 20,
  132. pages: null,
  133. loading: false,
  134. editDialogVisible: false,
  135. editDialogTitle: '新增账号',
  136. editType: 'add',
  137. ruleForm: {
  138. // 协议信息表单
  139. user_name: "",
  140. user_status: "",
  141. user_comment: "",
  142. user_pwd: "",
  143. },
  144. rules: {
  145. // 协议信息表单验证
  146. user_name: [
  147. { required: true, message: "请输入账号名称", trigger: "blur" },
  148. ],
  149. },
  150. ruleFormObj: {},
  151. roleId: '',
  152. msgIndex: null
  153. }
  154. },
  155. computed: {
  156. ...mapGetters(['systemSet']),
  157. noMore () {
  158. return this.PageIndex >= this.pages
  159. },
  160. disabled () {
  161. return this.loading || this.noMore
  162. }
  163. },
  164. watch: {
  165. searchInfo (val) {
  166. val.length === 0 && this.pageInit()
  167. }
  168. },
  169. created () {
  170. // 获取系统配置
  171. // if (this.systemSet) {
  172. // let obj
  173. // if (typeof this.systemSet === 'string') {
  174. // obj = JSON.parse(this.systemSet)
  175. // } else {
  176. // obj = this.systemSet
  177. // }
  178. // // console.log(obj)
  179. // const { PwdStruc, PwdLengthBegin, PwdLengthEnd } = obj
  180. // this.pwdStruc = PwdStruc
  181. // this.pwdLengthBegin = PwdLengthBegin
  182. // this.pwdLengthEnd = PwdLengthEnd
  183. // }
  184. if (!this.searchInfo) {
  185. this.accountList()
  186. } else {
  187. console.log(this.searchInfo)
  188. this.accountList()
  189. }
  190. },
  191. methods: {
  192. // 随机生成密码
  193. resetPwd () {
  194. this.ruleForm.PassWord = pwdProduce(this.pwdLengthBegin, this.pwdLengthEnd, this.pwdStruc)
  195. },
  196. // 编辑账号
  197. async saveEditAccount () {
  198. try {
  199. this.ruleForm.user_pwd = MD5(this.ruleForm.user_pwd)
  200. const res = await GeneralDataReception({
  201. serviceId: SERVICE_ID.accountScId,
  202. dataContent: JSON.stringify(this.ruleForm)
  203. })
  204. if (res.code == 0) {
  205. this.$message.success(res.message)
  206. this.resetForm('ruleForm')
  207. this.pageInit()
  208. } else {
  209. this.$message.error(res.message)
  210. }
  211. } catch (error) {
  212. console.log('出错了', error)
  213. }
  214. },
  215. // 新增账号
  216. async saveAddAccount () {
  217. try {
  218. this.ruleForm.user_pwd = MD5(this.ruleForm.user_pwd)
  219. const res = await GeneralDataReception({
  220. serviceId: SERVICE_ID.accountScId,
  221. dataContent: JSON.stringify(this.ruleForm)
  222. })
  223. if (res.code == 0) {
  224. this.$message.success(res.message)
  225. this.resetForm('ruleForm')
  226. this.pageInit()
  227. } else {
  228. this.$message.error(res.message)
  229. }
  230. } catch (error) {
  231. console.log('出错了', error)
  232. }
  233. },
  234. // 获取当前账号信息
  235. async getAccountInfo () {
  236. const res = await Query({
  237. id: DATACONTENT_ID.accountDetailsId,
  238. dataContent: [this.roleId]
  239. })
  240. if (res.code == 0) {
  241. const { listValues } = res.returnData
  242. const obj = listValues[0]
  243. this.ruleForm = obj
  244. this.ruleForm.event = 2
  245. } else {
  246. this.$message.error(res.message)
  247. }
  248. },
  249. // 新增/编辑-确认
  250. submitClickHandler () {
  251. this.$refs["ruleForm"].validate((valid) => {
  252. if (valid) {
  253. if (this.editType == 'add') {
  254. this.saveAddAccount()
  255. } else {
  256. this.saveEditAccount()
  257. }
  258. this.editDialogVisible = false
  259. } else {
  260. return false
  261. }
  262. });
  263. },
  264. // 滚动加载
  265. load () {
  266. this.PageIndex += 1
  267. this.accountList()
  268. },
  269. // 回到第一页
  270. pageInit () {
  271. this.PageIndex = 1
  272. this.accountArr = []
  273. this.accountList()
  274. },
  275. // 查询
  276. getSearchData (val) {
  277. this.searchInfo = val
  278. this.pageInit()
  279. },
  280. // 清除查询
  281. clearSearchData () {
  282. this.searchInfo = ''
  283. this.pageInit()
  284. },
  285. // 修改状态
  286. async userActiveToggle (item) {
  287. item.event = 2
  288. item.user_status = item.Flag ? 1 : 2
  289. try {
  290. const result = await GeneralDataReception({
  291. serviceId: SERVICE_ID.accountScId,
  292. dataContent: JSON.stringify(item)
  293. })
  294. if (result.code == 0) {
  295. this.pageInit()
  296. this.$message.success(result.message)
  297. } else {
  298. this.$message.error(result.$message)
  299. }
  300. } catch (error) {
  301. console.log('出错了', error)
  302. }
  303. },
  304. deleteUser (user) {
  305. this.dialogVisible = true
  306. this.deleteUserName = user.UName
  307. this.ruleFormObj = user
  308. },
  309. toEdit (userId) {
  310. this.editDialogVisible = true
  311. this.editType = 'edit'
  312. this.editDialogTitle = '编辑账号'
  313. this.roleId = userId
  314. this.getAccountInfo()
  315. },
  316. addAccount () {
  317. this.editDialogTitle = '新增账号'
  318. this.editDialogVisible = true
  319. this.editType = 'add'
  320. this.ruleForm = {}
  321. this.ruleForm.event = 1
  322. // this.$router.push({
  323. // path: '/account/accountAdd'
  324. // })
  325. },
  326. // 重置
  327. resetForm (formName) {
  328. this.$refs[formName].resetFields()
  329. this.editDialogVisible = false
  330. },
  331. // 获取列表
  332. async accountList () {
  333. try {
  334. this.loading = true
  335. const result = await Query({
  336. id: DATACONTENT_ID.accountTableId,
  337. needPage: this.PageIndex,
  338. dataContent: [this.searchInfo]
  339. })
  340. if (result.code == 0) {
  341. this.loading = false
  342. const newDatas = result.returnData.listValues
  343. if (newDatas && newDatas.length) {
  344. this.pages = result.returnData.pages
  345. newDatas.forEach(element => {
  346. element.Flag = element.user_status == 1 ? true : false
  347. this.accountArr.push(element)
  348. })
  349. this.msgIndex = this.PageIndex
  350. } else {
  351. this.pages = this.msgIndex
  352. this.PageIndex = this.msgIndex
  353. }
  354. } else {
  355. this.$message.error(result.message)
  356. }
  357. } catch (error) {
  358. console.log('出错了', error)
  359. }
  360. },
  361. // 删除接口
  362. async del () {
  363. this.ruleFormObj.event = 3
  364. const result = await GeneralDataReception({
  365. serviceId: SERVICE_ID.accountScId,
  366. dataContent: JSON.stringify(this.ruleFormObj)
  367. })
  368. if (result.code == 0) {
  369. this.dialogVisible = false
  370. this.$message.success(result.message)
  371. this.pageInit()
  372. } else if (result.code == -1) {
  373. this.$message.error('后端错误,稍后请重试')
  374. } else {
  375. this.$message.success(result.message)
  376. }
  377. },
  378. // 账号权限
  379. authAccount (item) {
  380. this.roleId = item.user_id
  381. this.$router.push({
  382. path: '/account/accountAuth',
  383. query: { userId: this.roleId }
  384. })
  385. }
  386. }
  387. }
  388. </script>
  389. <style lang="scss" scoped>
  390. .account-home {
  391. padding: 16px 32px 32px 32px;
  392. .account-header {
  393. margin-bottom: 30px;
  394. line-height: 32px;
  395. width: 100%;
  396. display: flex;
  397. justify-content: space-between;
  398. .btn-add {
  399. width: 120px;
  400. height: 48px;
  401. background: #f5f7fa;
  402. border: 1px solid #b4b7cb;
  403. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  404. border-radius: 6px;
  405. font-size: 16px;
  406. font-weight: bold;
  407. color: #6f81bc;
  408. }
  409. .status {
  410. align-items: center;
  411. .icon {
  412. width: 14px;
  413. height: 14px;
  414. background: #2d67e3;
  415. border-radius: 2px;
  416. display: inline-block;
  417. vertical-align: middle;
  418. margin-right: 10px;
  419. position: relative;
  420. top: -2px;
  421. }
  422. &:last-child {
  423. margin-right: 0;
  424. }
  425. .status2 {
  426. margin: 0 28px;
  427. .icon {
  428. background: #eb2f3b;
  429. }
  430. }
  431. .status3 {
  432. .icon {
  433. background: #afb4bf;
  434. }
  435. }
  436. }
  437. }
  438. .content-box {
  439. height: calc(100vh - 256px);
  440. overflow-y: auto;
  441. overflow-x: hidden;
  442. @media only screen and (min-width: 1920px) {
  443. .el-col-xl-4-8 {
  444. width: 20%;
  445. }
  446. }
  447. .account-box {
  448. min-height: 140px;
  449. margin-bottom: 24px;
  450. .account-box-wrap {
  451. position: relative;
  452. padding: 24px;
  453. background: #ffffff;
  454. box-shadow: 0px 3px 3px 0px rgba(0, 0, 0, 0.1);
  455. border-radius: 4px;
  456. overflow: hidden;
  457. }
  458. .headOffline {
  459. width: 100%;
  460. height: 4px;
  461. background: #f25555;
  462. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  463. border-radius: 4px;
  464. position: absolute;
  465. left: 0;
  466. top: 0;
  467. }
  468. .headOnline {
  469. background: #2d67e3;
  470. width: 100%;
  471. height: 4px;
  472. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  473. border-radius: 4px;
  474. position: absolute;
  475. left: 0;
  476. top: 0;
  477. }
  478. .headDisabled {
  479. background: #cfd6e2;
  480. width: 100%;
  481. height: 4px;
  482. box-shadow: 0px 6px 7px 0px rgba(0, 0, 0, 0.06);
  483. border-radius: 4px;
  484. position: absolute;
  485. left: 0;
  486. top: 0;
  487. }
  488. .el-row {
  489. margin: 8px 0;
  490. }
  491. .flexLeft {
  492. display: flex;
  493. justify-content: flex-end;
  494. flex-direction: row;
  495. }
  496. .del {
  497. cursor: pointer;
  498. i {
  499. font-size: 14px;
  500. font-weight: 600;
  501. color: #606266;
  502. }
  503. }
  504. .nameBox {
  505. display: flex;
  506. .name {
  507. font-size: 16px;
  508. font-weight: bold;
  509. color: #303133;
  510. max-width: 120px;
  511. white-space: nowrap;
  512. overflow: hidden;
  513. text-overflow: ellipsis;
  514. }
  515. .loger {
  516. width: 14px;
  517. height: 14px;
  518. margin-left: 24px;
  519. background: url("../../../assets/status/ic_edit_default.png")
  520. no-repeat;
  521. background-size: 100% 100%;
  522. cursor: pointer;
  523. }
  524. .loger:hover {
  525. background: url("../../../assets/status/ic_edit_hovar.png") no-repeat;
  526. background-size: 100% 100%;
  527. }
  528. .cap-auth {
  529. margin-left: 12px;
  530. background-image: url("../../../assets/status/ic_edit_authorization.png");
  531. &:hover {
  532. background-image: url("../../../assets/status/ic_edit_authorization_hover.png");
  533. }
  534. }
  535. }
  536. .content {
  537. margin-top: 14px;
  538. font-size: 14px;
  539. }
  540. .used {
  541. font-size: 14px;
  542. font-weight: 400;
  543. color: #2d67e3;
  544. }
  545. span {
  546. font-size: 16px;
  547. font-weight: 400;
  548. color: #909399;
  549. }
  550. }
  551. }
  552. .del-dialog {
  553. .del-content {
  554. font-size: 16px;
  555. font-family: Microsoft YaHei;
  556. font-weight: 400;
  557. color: #101611;
  558. .el-icon-error {
  559. vertical-align: sub;
  560. font-size: 26px;
  561. }
  562. }
  563. }
  564. }
  565. </style>