index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <template>
  2. <div>
  3. <com-head :options="headList">
  4. <el-form label-width="84px" inline="true">
  5. <el-form-item label="角色名称:">
  6. <el-input
  7. v-model="search.state.nickName"
  8. placeholder="请输入"
  9. ></el-input>
  10. </el-form-item>
  11. <el-form-item label="所属架构:">
  12. <com-company v-model="search.state.deptId" />
  13. </el-form-item>
  14. <el-form-item class="searh-btns">
  15. <el-button type="primary" @click="search.submit">查询</el-button>
  16. <el-button type="primary" plain @click="search.reset">重置</el-button>
  17. </el-form-item>
  18. </el-form>
  19. </com-head>
  20. <div class="body-layer" style="padding-top: 8px">
  21. <div class="body-but">
  22. <el-button type="primary" @click="newAddclick">新增角色</el-button>
  23. <!-- <h3 style="visibility: hidden;">用户列表</h3> -->
  24. </div>
  25. <el-table
  26. class="user-table"
  27. ref="multipleTable"
  28. :data="dataList.state"
  29. tooltip-effect="dark"
  30. style="width: 100%;max-height:480px"
  31. @row-click="selectRow"
  32. >
  33. <el-table-column label="序号" width="55" v-slot:default="{ $index }">
  34. <div style="text-align: center">
  35. {{ pag.state.size * (pag.state.currPage - 1) + $index + 1 }}
  36. </div>
  37. </el-table-column>
  38. <el-table-column label="角色名称" prop="userName"></el-table-column>
  39. <el-table-column label="角色类型" prop="nickName"></el-table-column>
  40. <el-table-column
  41. label="所属架构"
  42. prop="departmentName"
  43. ></el-table-column>
  44. <el-table-column label="创建人" prop="roleName"></el-table-column>
  45. <el-table-column label="创建时间" prop="roleName"></el-table-column>
  46. <el-table-column label="操作" v-slot:default="{ row }">
  47. <!-- v-if="auth.update || auth.updatePwd || auth.delete" v-if="auth.update"-->
  48. <!-- row.roleKey == roleKey[user.roleKey] -->
  49. <template v-if="user.roleKey !== 'admin-ordinary'">
  50. <span class="oper-span" @click="delInfo(row)" v-power="'view'"
  51. >查看</span
  52. >
  53. <span class="oper-span" @click="updateInfo(row)" v-power="'edit'"
  54. >编辑</span
  55. >
  56. <!-- v-if="auth.delete" -->
  57. <span
  58. class="oper-span"
  59. style="color: var(--primaryColor)"
  60. @click="delInfo(row)"
  61. v-power="'del'"
  62. >删除</span
  63. >
  64. </template>
  65. </el-table-column>
  66. </el-table>
  67. <com-pagination
  68. @size-change="pag.sizeChange"
  69. @current-change="pag.currentChange"
  70. :current-page="pag.state.currPage"
  71. :page-size="pag.state.size"
  72. layout="total, sizes, prev, pager, next, jumper"
  73. :total="pag.state.total"
  74. />
  75. </div>
  76. <com-dialog
  77. title="编辑用户"
  78. v-model:show="oper.state.show"
  79. @submit="operItem"
  80. width="540"
  81. >
  82. <el-form ref="form" :model="form" label-width="90px" class="user-from">
  83. <el-form-item label="用户姓名" class="mandatory">
  84. <el-input
  85. v-model.trim="editName"
  86. placeholder="请输入"
  87. maxlength="15"
  88. ></el-input>
  89. </el-form-item>
  90. </el-form>
  91. </com-dialog>
  92. <com-dialog
  93. title="新增角色"
  94. @quit="
  95. newData = {};
  96. deptIdList = [];
  97. "
  98. v-model:show="newShow"
  99. @submit="newSubmit"
  100. width="540"
  101. >
  102. <el-form ref="form" :model="form" label-width="90px" class="user-from">
  103. <el-form-item label="角色名称:" class="mandatory">
  104. <el-input
  105. maxlength="15"
  106. v-model="newData.nickName"
  107. placeholder="请输入"
  108. ></el-input>
  109. </el-form-item>
  110. <el-form-item
  111. label="所属架构:"
  112. v-if="user.roleKey !== 'admin-ordinary'"
  113. >
  114. <el-input
  115. maxlength="15"
  116. disabled="true"
  117. v-model="newData.userRokename"
  118. placeholder="请输入"
  119. ></el-input>
  120. </el-form-item>
  121. <el-row :gutter="20">
  122. <el-col :span="12">
  123. <div class="grid-content bg-purple">
  124. <div class="title">功能权限</div>
  125. <el-tree
  126. ref="tree"
  127. :data="roledata"
  128. highlight-current
  129. show-checkbox
  130. :current-node-key="nodekey"
  131. node-key="id"
  132. @check="handleClick"
  133. @node-click="handClick"
  134. :props="{ children: 'children', label: 'label' }"
  135. />
  136. <!-- @current-change="handcurrentChange"
  137. @check-change="handcheckchange"-->
  138. </div>
  139. </el-col>
  140. <el-col :span="12">
  141. <div class="grid-content bg-purple">
  142. <div class="title">数据权限</div>
  143. <el-radio-group
  144. v-if="selectShow"
  145. v-model="radio"
  146. @change="radioChange"
  147. >
  148. <el-radio
  149. style="line-height:28px"
  150. v-for="item in roleSelct"
  151. :key="item.id"
  152. :label="item.id"
  153. size="medium"
  154. >{{ item.value }}</el-radio
  155. >
  156. </el-radio-group>
  157. </div>
  158. </el-col>
  159. </el-row>
  160. </el-form>
  161. </com-dialog>
  162. </div>
  163. </template>
  164. <script>
  165. import { reactive, ref, toRefs, onMounted } from "vue";
  166. import getTableState from "@/state/tableRef";
  167. import comDialog from "@/components/dialog";
  168. import comHead from "@/components/head";
  169. import comCompany from "@/components/company-select";
  170. import comPagination from "@/components/pagination";
  171. // import roleCompany from "@/components/role-select";
  172. // import comSelect from "@/components/company-select";
  173. import auth from "@/state/viewAuth";
  174. import user from "@/state/user";
  175. import axios from "axios";
  176. // import { encryption } from "@/util";
  177. import { PHONE, EPSW } from "@/constant/REG";
  178. import { ADMIN_USER_ID } from "@/constant";
  179. import {
  180. getTreeselect,
  181. getUserList,
  182. updateUser,
  183. deleUser,
  184. changeUserStatus,
  185. userAdd,
  186. userEdit,
  187. } from "@/request/config";
  188. import { getApp } from "../../app";
  189. export default {
  190. name: "user",
  191. setup() {
  192. const flag = ref(true);
  193. const state = getTableState({
  194. getUrl: getUserList,
  195. updateUrl: updateUser,
  196. operAttr: {
  197. nickName: "",
  198. userName: "",
  199. deptId: "",
  200. password: "",
  201. confirmPwd: "",
  202. roleId: "",
  203. maxlevel: 1,
  204. },
  205. searchAttr: { nickName: "", status: "", deptId: "" },
  206. });
  207. const headList = ref([{ name: "角色管理", value: 2 }]);
  208. const roleKey = ref({
  209. admin: "admin-dept",
  210. "admin-dept": "admin-ordinary",
  211. });
  212. const operRoleId = ref("");
  213. const updateInfo = (row) => {
  214. if (!row.status) {
  215. return getApp().$message.error("请先启用用户", "提示");
  216. }
  217. data.editName = row.nickName;
  218. operRoleId.value = row.roleId;
  219. state.oper.value.readyUpdate(row);
  220. };
  221. const delInfo = async (row) => {
  222. let isOk = await getApp().$confirm(
  223. "用户被删除后,无法登陆使用,无法编辑场景(可将该用户关联的相机绑定到其他管理员),确认要删除组织吗?",
  224. "删除"
  225. );
  226. if (isOk) {
  227. await axios.post(deleUser, { id: row.id });
  228. getApp().$message({ message: "操作成功", type: "success" });
  229. state.search.value.submit();
  230. }
  231. };
  232. const getTreedata = async () => {
  233. let res = await axios.get(getTreeselect, {});
  234. data.treedata = res.data;
  235. console.log("data.treedata", data.treedata);
  236. // getApp().$ref.treeBox.setCurrentKey(user.info.id)
  237. };
  238. const newAddclick = () => {
  239. data.newShow = true;
  240. };
  241. const data = reactive({
  242. newShow: false,
  243. editName: "", //修改编辑用户名称
  244. deptIdList: [],
  245. radio: 1,
  246. radioData: {},
  247. nodekey: "",
  248. selectShow: false,
  249. roleSelct: [
  250. { id: 1, value: "全部数据" },
  251. { id: 2, value: "所属组织及下级组织数据" },
  252. { id: 3, value: "所属组织内部数据" },
  253. { id: 4, value: "个人创建数据" },
  254. ],
  255. selectData: {},
  256. roledata: [
  257. {
  258. id: 1,
  259. label: "场景管理",
  260. value: true,
  261. children: [
  262. {
  263. id: 14,
  264. label: "查看",
  265. value: false,
  266. },
  267. {
  268. id: 19,
  269. label: "删除",
  270. value: false,
  271. },
  272. {
  273. id: 10,
  274. label: "编辑",
  275. value: false,
  276. },
  277. ],
  278. },
  279. {
  280. id: 2,
  281. label: "火调管理",
  282. value: true,
  283. children: [
  284. {
  285. id: 24,
  286. label: "查看",
  287. value: false,
  288. },
  289. {
  290. id: 29,
  291. label: "删除",
  292. value: false,
  293. },
  294. {
  295. id: 20,
  296. label: "编辑",
  297. value: false,
  298. },
  299. ],
  300. },
  301. ],
  302. treedata: [],
  303. newData: {
  304. userName: "",
  305. userId: "",
  306. userRokename: "全部数据",
  307. password: "",
  308. userRole: "",
  309. },
  310. });
  311. onMounted(async () => {
  312. getTreedata();
  313. });
  314. return {
  315. ...state,
  316. ...toRefs(data),
  317. flag,
  318. getTreedata,
  319. headList,
  320. delInfo,
  321. updateInfo,
  322. auth,
  323. user,
  324. operRoleId,
  325. ADMIN_USER_ID,
  326. roleKey,
  327. newAddclick,
  328. };
  329. },
  330. methods: {
  331. //@check事件
  332. handleClick(data, checked) {
  333. console.log(checked);
  334. console.log(data);
  335. let CurrentKey = this.$refs.tree.getCurrentKey();
  336. if (
  337. checked.checkedKeys.includes(data.id) &&
  338. !data.value &&
  339. CurrentKey == data.id
  340. ) {
  341. this.setselectShow(data, data.id);
  342. } else {
  343. this.selectShow = null;
  344. }
  345. },
  346. radioChange(val) {
  347. let id = this.selectShow.id;
  348. this.radioData[id] = val;
  349. console.log("radioChange", val);
  350. },
  351. handClick(data) {
  352. let checkedNodes = this.$refs.tree.getCheckedNodes();
  353. let selectShow = checkedNodes.find((ele) => data.id == ele.id) || null;
  354. if (!data.value) {
  355. this.setselectShow(selectShow, data.id);
  356. }
  357. console.log("handClick", this.selectShow);
  358. },
  359. setselectShow(selectShow, id) {
  360. this.selectShow = selectShow;
  361. this.radio = this.radioData[id] || 1;
  362. },
  363. handcurrentChange(a, b) {
  364. console.log("handcurrentChange", a, b);
  365. console.log("ref", this.selectShow);
  366. },
  367. changeDeptId(val) {
  368. this.newData.deptId = val && val[val.length - 1];
  369. },
  370. async newSubmit() {
  371. console.log("newSubmit", this.user, this.newData);
  372. if (!this.newData.nickName) {
  373. return this.$message.error("请输入用户姓名", "提示");
  374. }
  375. if (!this.newData.roleId) {
  376. return this.$message.error("请选择用户角色", "提示");
  377. }
  378. console.log(PHONE.REG.test(this.newData.userName), this.newData.userName);
  379. if (!this.newData.userName) {
  380. return this.$message.error("请选择用户账户", "提示");
  381. } else if (!PHONE.REG.test(this.newData.userName)) {
  382. return this.$message.error(PHONE.tip, "提示");
  383. }
  384. if (!this.newData.psw) {
  385. return this.$message.error("请输入登录密码", "提示");
  386. } else if (!EPSW.REG.test(this.newData.psw)) {
  387. return this.$message.error(EPSW.tip, "提示");
  388. }
  389. let apiinfo = await axios.post(userAdd, {
  390. nickName: this.newData.nickName,
  391. password: this.newData.psw,
  392. userName: this.newData.userName,
  393. roleId: this.newData.roleId,
  394. deptId: this.newData.deptId,
  395. // ...this.newData
  396. });
  397. this.$message({ message: apiinfo.msg || "成功", type: "success" });
  398. // await this.$confirm('每个组织只能创建一个总管理员~', '新增用户')
  399. this.newData = {};
  400. this.deptIdList = [];
  401. this.newShow = false;
  402. this.dataList.refer();
  403. },
  404. async operItem() {
  405. if (!this.editName) {
  406. return this.$message.error("请输入用户名称", "提示");
  407. }
  408. console.log("state.oper", this.oper);
  409. await axios.post(userEdit, {
  410. id: this.oper.state.id,
  411. nickName: this.editName,
  412. });
  413. this.$message({ message: "编辑成功", type: "success" });
  414. this.oper.reset();
  415. this.editName = "";
  416. this.dataList.refer();
  417. },
  418. async changeUserStatus(row, d) {
  419. let msg = row.status
  420. ? `用户被禁用后,无法登录使用,无法编辑场景(可将该用户关联的相机绑定到其它管理员)。确定要禁用吗?`
  421. : `用户被启用后,可正常登录使用。确定要启用吗?`;
  422. try {
  423. if (d || (await this.$confirm(msg, "提示"))) {
  424. await axios.post(changeUserStatus, {
  425. status: Number(!row.status),
  426. userId: row.id,
  427. });
  428. this.dataList.refer();
  429. }
  430. return true;
  431. } catch {
  432. return false;
  433. }
  434. },
  435. },
  436. components: {
  437. "com-dialog": comDialog,
  438. "com-head": comHead,
  439. "com-company": comCompany,
  440. // "com-role": roleCompany,
  441. "com-pagination": comPagination,
  442. // "com-select": comSelect
  443. },
  444. };
  445. </script>
  446. <style lang="scss" scoped>
  447. .grid-content {
  448. border: 1px solid #e8e8e8;
  449. border-bottom: none;
  450. .title {
  451. background: #fafafa;
  452. padding: 12px 10px;
  453. border-bottom: 1px solid #ebeef5;
  454. line-height: 20px;
  455. }
  456. .el-radio-group {
  457. width: 100%;
  458. .el-radio {
  459. padding: 12px 10px;
  460. border-bottom: 1px solid #ebeef5;
  461. display: block;
  462. margin-right: 0;
  463. &:last-child {
  464. // border-bottom: none;
  465. }
  466. }
  467. }
  468. }
  469. .body-layer {
  470. .body-but {
  471. text-align: right;
  472. margin-bottom: 15px;
  473. }
  474. }
  475. .table-ctrl-right {
  476. .search-scene {
  477. margin: 0 20px 0 26px;
  478. }
  479. i {
  480. margin-left: 20px;
  481. font-size: 1.7rem;
  482. vertical-align: middle;
  483. cursor: pointer;
  484. &.active {
  485. color: var(--primaryColor);
  486. }
  487. }
  488. }
  489. .user-from {
  490. // width: 380px;
  491. margin: 0 auto;
  492. }
  493. .tip {
  494. position: fixed;
  495. left: 50%;
  496. top: 50%;
  497. z-index: 999;
  498. &::before {
  499. content: "密码重置为Fcb20210225,可登录修改";
  500. position: absolute;
  501. width: 205px;
  502. left: 50%;
  503. transform: translateX(-50%);
  504. bottom: 100%;
  505. border-radius: 4px;
  506. padding: 10px;
  507. z-index: 2000;
  508. font-size: 12px;
  509. line-height: 1.2;
  510. min-width: 10px;
  511. word-wrap: break-word;
  512. background: #303133;
  513. color: #fff;
  514. margin-bottom: 6px;
  515. }
  516. &::after {
  517. content: "";
  518. position: absolute;
  519. display: block;
  520. width: 0;
  521. height: 0;
  522. bottom: 100%;
  523. left: 50%;
  524. transform: translateX(-50%);
  525. border-color: transparent;
  526. border-style: solid;
  527. border-width: 6px;
  528. border-top-color: #303133;
  529. border-bottom-width: 0;
  530. }
  531. }
  532. .maker {
  533. font-weight: 400;
  534. color: #969799;
  535. line-height: 20px;
  536. }
  537. </style>
  538. <style lang="less">
  539. .user-table.el-table .cell {
  540. overflow: inherit;
  541. }
  542. .el-tree {
  543. max-height: 400px;
  544. overflow-y: auto;
  545. border-bottom: 1px solid #ebeef5;
  546. .el-tree-node__content {
  547. border-bottom: 1px solid #ebeef5;
  548. padding: 12px 10px;
  549. &:last-child {
  550. // border-bottom: none;
  551. }
  552. }
  553. }
  554. </style>