index.vue 16 KB

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