index.vue 15 KB

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