accountHome.vue 20 KB

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