manage.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <template>
  2. <basic-container class="mt-10">
  3. <avue-crud
  4. :option="option"
  5. :data="data"
  6. ref="crud"
  7. v-model="form"
  8. v-model:page="page"
  9. :before-open="beforeOpen"
  10. @current-change="currentChange"
  11. @size-change="sizeChange"
  12. @refresh-change="refreshChange"
  13. @on-load="onLoad"
  14. >
  15. <template #menu="{ row }">
  16. <el-button icon="Open" type="primary" text @click="Enable(row)">
  17. {{ row.clientId.indexOf('project_web') === -1 ? '启用' : '停用' }}
  18. </el-button>
  19. <el-button icon="Refresh" type="primary" text @click="restPwd(row)">
  20. 重置密码
  21. </el-button>
  22. </template>
  23. <template #status="{ row }">
  24. <el-tag
  25. :type="row.clientId.indexOf('project_web') === -1 ? 'danger' : ''"
  26. >
  27. {{ row.clientId.indexOf('project_web') === -1 ? '停用' : '启用' }}
  28. </el-tag>
  29. </template>
  30. <template #menu-left>
  31. <el-button type="primary" plain @click="showQrCode = true"
  32. >通过微信邀请
  33. </el-button>
  34. </template>
  35. </avue-crud>
  36. <el-dialog
  37. v-model="showEdit"
  38. append-to-body
  39. center
  40. title="用户信息设置"
  41. width="50%"
  42. >
  43. <div>
  44. <el-form
  45. ref="form"
  46. :model="userInfoForm"
  47. :rules="rules"
  48. class="mt-20"
  49. label-width="100px"
  50. >
  51. <div class="flex flex-center">
  52. <el-form-item class="full-width" label="登录账号" prop="name">
  53. <el-input
  54. v-model="userInfoForm.account"
  55. clearable
  56. placeholder="输入用户名称"
  57. />
  58. </el-form-item>
  59. <el-form-item
  60. class="full-width mr-20"
  61. label="真实姓名"
  62. :rules="rules"
  63. prop="realName"
  64. >
  65. <el-input
  66. v-model="userInfoForm.realName"
  67. clearable
  68. placeholder="输入真实姓名"
  69. >
  70. </el-input>
  71. </el-form-item>
  72. </div>
  73. <div class="flex flex-center">
  74. <el-form-item label="手机号码" class="full-width" prop="phone">
  75. <el-input
  76. v-model="userInfoForm.phone"
  77. clearable
  78. placeholder="输入手机号码"
  79. >
  80. </el-input>
  81. </el-form-item>
  82. <el-form-item
  83. class="full-width mr-20"
  84. label="登陆密码"
  85. prop="password"
  86. >
  87. <el-input
  88. v-model="userInfoForm.password"
  89. :disabled="form.type !== 'add'"
  90. clearable
  91. :placeholder="form.type !== 'add' ? '******' : '输入登陆密码'"
  92. >
  93. </el-input>
  94. </el-form-item>
  95. </div>
  96. <div class="flex flex-align-center">
  97. <span class="ml-20 bold">部门选择</span>
  98. <el-form-item class="flex">
  99. <el-select
  100. class="mt-20"
  101. v-model="userInfoForm.deptId"
  102. style="width: 250px; margin-left: -75px"
  103. placeholder="选择用户所属部门"
  104. >
  105. <el-option
  106. v-for="item in deptList"
  107. :key="item.id"
  108. :label="item.deptName"
  109. :value="item.id"
  110. />
  111. </el-select>
  112. </el-form-item>
  113. </div>
  114. <div class="flex flex-col mt-10">
  115. <span class="ml-20 bold">职务选择</span>
  116. <el-form-item class="flex flex-wrap">
  117. <div class="flex flex-center padding pointer">
  118. <el-radio-group size="large" v-model="userInfoForm.roleIds">
  119. <el-radio v-for="item in jobs" :key="item.id" :label="item.id"
  120. >{{ item.roleName }}
  121. </el-radio>
  122. </el-radio-group>
  123. </div>
  124. </el-form-item>
  125. </div>
  126. <div class="flex flex-col" style="margin-top: -10px">
  127. <div class="flex flex-align-center">
  128. <span class="bold ml-20">管理股室</span>
  129. <el-checkbox
  130. size="large"
  131. style="margin-left: 33px"
  132. v-model="checkAll"
  133. @change="choseAll"
  134. >全选
  135. </el-checkbox>
  136. </div>
  137. <el-form-item class="flex flex-wrap">
  138. <div class="flex flex-center padding pointer">
  139. <el-checkbox
  140. v-model="item.checked"
  141. :label="item.id"
  142. size="large"
  143. v-for="item in deptList"
  144. :key="item.id"
  145. @change="deptChose($event, item)"
  146. >
  147. {{ item.deptName }}
  148. </el-checkbox>
  149. </div>
  150. </el-form-item>
  151. </div>
  152. <div class="flex flex-center">
  153. <base-button
  154. title="取消"
  155. type="0"
  156. icon="Close"
  157. @click="showEdit = false"
  158. />
  159. <base-button
  160. class="ml-10"
  161. title="保存"
  162. icon="Check"
  163. @click="roleSave"
  164. />
  165. </div>
  166. </el-form>
  167. </div>
  168. </el-dialog>
  169. <el-dialog
  170. v-model="showQrCode"
  171. title="邀请二维码"
  172. width="500"
  173. @close="closeCode"
  174. >
  175. <div>
  176. <div class="full-width flex flex-center">
  177. <span class="mr-20">用户所属部门</span>
  178. <el-select
  179. v-model="userInfoForm.deptId"
  180. placeholder="选择用户所属部门"
  181. @change="qrCodeSelect"
  182. >
  183. <el-option
  184. v-for="item in deptList"
  185. :key="item.id"
  186. :label="item.deptName"
  187. :value="item.id"
  188. />
  189. </el-select>
  190. </div>
  191. <div v-if="qrCodeText.length > 0" class="flex flex-center flex-col">
  192. <vue-qr
  193. class="mt-20"
  194. :currentLevel="3"
  195. :logoCornerRadius="4"
  196. :logoScale="0.25"
  197. :logoSrc="logoSrc"
  198. :text="qrCodeText"
  199. size="260"
  200. />
  201. <span>- 复制二维码图片,通过微信发送邀请 -</span>
  202. </div>
  203. <el-empty v-else description="暂无数据" />
  204. </div>
  205. </el-dialog>
  206. </basic-container>
  207. </template>
  208. <route>
  209. {
  210. name: '用户管理',
  211. meta: { 'back':true,'showMsg' : "如果手机号为用户微信绑定的手机号时,微信小程序将自动登录,并同步信息!"}
  212. }
  213. </route>
  214. <script>
  215. import BasicContainer from '@/components/basic-container/main.vue'
  216. import { useStore } from '@/store/user.js'
  217. import baseButton from '@/components/base-button.vue'
  218. import { ElMessageBox } from 'element-plus'
  219. import VueQr from 'vue-qr/src/packages/vue-qr.vue'
  220. export default {
  221. name: 'manage',
  222. components: {
  223. BasicContainer,
  224. baseButton,
  225. VueQr
  226. },
  227. setup() {
  228. const user = useStore()
  229. return { user }
  230. },
  231. data() {
  232. return {
  233. showAdd: false,
  234. showQrCode: false,
  235. showEdit: false,
  236. qrCodeText: '',
  237. sessionId: '',
  238. logoSrc: new URL('@/assets/img/logo.png', import.meta.url).href,
  239. form: {},
  240. page: {
  241. curren: 1,
  242. size: 10
  243. },
  244. data: [],
  245. option: {
  246. align: 'center',
  247. menuAlign: 'center',
  248. menuWidth: 240,
  249. size: 'mini',
  250. addBtn: true,
  251. addBtnText: '添加用户',
  252. viewBtn: false,
  253. delBtn: false,
  254. refreshBtn: true,
  255. columnBtn: false,
  256. labelWidth: 140,
  257. border: true,
  258. column: [
  259. {
  260. label: '登录账号',
  261. prop: 'account',
  262. display: false,
  263. width: 170
  264. },
  265. {
  266. label: '真实姓名',
  267. prop: 'realName'
  268. },
  269. {
  270. label: '手机号码',
  271. prop: 'phone'
  272. },
  273. {
  274. label: '职务',
  275. prop: 'roleName'
  276. },
  277. {
  278. label: '状态',
  279. prop: 'status'
  280. }
  281. ]
  282. },
  283. jobs: [],
  284. deptList: [],
  285. checkAll: false,
  286. userInfoForm: {
  287. name: '',
  288. realName: '',
  289. phone: '',
  290. password: '',
  291. roleIds: '',
  292. deptIds: [],
  293. deptId: ''
  294. },
  295. rules: {
  296. name: {
  297. required: true,
  298. message: '用户名称不能为空!',
  299. trigger: 'blur'
  300. },
  301. realName: {
  302. required: true,
  303. message: '真实姓名不能为空!',
  304. trigger: 'blur'
  305. },
  306. phone: [
  307. {
  308. required: true,
  309. message: '手机号码不能为空!',
  310. trigger: 'blur'
  311. },
  312. {
  313. min: 11,
  314. max: 11,
  315. message: '请填写正确的手机号码!',
  316. trigger: 'blur'
  317. }
  318. ],
  319. password: [
  320. { required: true, message: '请输入密码', trigger: 'blur' },
  321. { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
  322. ]
  323. }
  324. }
  325. },
  326. created() {
  327. this.getOrg()
  328. this.getJobList()
  329. },
  330. methods: {
  331. onLoad() {
  332. this.loading = true
  333. this.page.current = this.page.currentPage
  334. this.page.size = this.page.pageSize
  335. const data = { deptId: this.user.info.deptId }
  336. console.log(this.page)
  337. this.$api.role
  338. .roleList(Object.assign(this.page, data))
  339. .then(res => {
  340. this.loading = false
  341. if (res.code === 200) {
  342. this.data = res.data.records
  343. this.page.total = res.data.total
  344. } else {
  345. this.$message.error(res.msg)
  346. }
  347. })
  348. .finally(() => {
  349. this.loading = false
  350. })
  351. },
  352. Enable(row) {
  353. this.$confirm('确定启用/停用该用户?', {
  354. confirmButtonText: '确定',
  355. cancelButtonText: '取消',
  356. type: 'warning'
  357. }).then(() => {
  358. this.$api.role
  359. .roleStart({
  360. userId: row.id,
  361. status: row.clientId.indexOf('project_web') > -1 ? 0 : 1
  362. })
  363. .then(res => {
  364. if (res.code === 200) {
  365. this.$message.success(res.msg)
  366. this.onLoad()
  367. } else {
  368. this.$message.error(res.msg)
  369. }
  370. })
  371. })
  372. },
  373. beforeOpen(done, type) {
  374. this.form.type = type
  375. if (type === 'edit') {
  376. this.rowEdit()
  377. } else if (type === 'add') {
  378. this.userInfoForm = {
  379. name: '',
  380. realName: '',
  381. phone: '',
  382. password: '',
  383. roleIds: '',
  384. deptIds: [],
  385. deptId: ''
  386. }
  387. this.deptList.map(e => (e.checked = false))
  388. this.showEdit = true
  389. } else {
  390. done()
  391. }
  392. },
  393. rowEdit() {
  394. if (this.form.clientId.indexOf('project_web') === -1) {
  395. this.$message.error('该账号已经停用,无需进行编辑!')
  396. return
  397. }
  398. this.userInfoForm.name = this.form.name
  399. this.userInfoForm.realName = this.form.realName
  400. this.userInfoForm.phone = this.form.phone
  401. this.userInfoForm.password = this.form.password
  402. this.userInfoForm.deptId = this.form.deptId
  403. this.jobs.find(e => {
  404. const temp = this.form.roleId.split(',').find(sub => sub === e.id)
  405. if (temp) {
  406. this.userInfoForm.roleIds = temp
  407. }
  408. return temp
  409. })
  410. this.$api.role.managerList({ userId: this.form.id }).then(res => {
  411. if (res.code === 200) {
  412. res.data.forEach(ele => {
  413. const tmp = this.deptList.findIndex(sub => sub.id === ele.deptId)
  414. if (tmp > -1) {
  415. this.deptList[tmp].checked = true
  416. }
  417. this.userInfoForm.deptIds = this.deptList.map(e => e.id)
  418. })
  419. if (
  420. this.deptList.filter(e => e.checked).length === this.deptList.length
  421. ) {
  422. this.checkAll = true
  423. } else {
  424. this.checkAll = false
  425. }
  426. this.showEdit = true
  427. }
  428. })
  429. },
  430. currentChange(currentPage) {
  431. this.page.current = currentPage
  432. },
  433. sizeChange(pageSize) {
  434. this.page.size = pageSize
  435. },
  436. refreshChange() {
  437. this.onLoad()
  438. },
  439. getJobList() {
  440. this.$api.role.jobList({ roleAlias: 'post' }).then(res => {
  441. if (res.code === 200) {
  442. this.jobs = res.data
  443. }
  444. })
  445. },
  446. getOrg() {
  447. this.$api.role.deptList().then(res => {
  448. if (res.code === 200) {
  449. this.showOrg = true
  450. this.deptList = res.data.map(e => {
  451. e.checked = false
  452. return e
  453. })
  454. } else {
  455. this.$message.error(res.msg)
  456. }
  457. })
  458. },
  459. choseAll(res) {
  460. this.deptList.map(e => {
  461. e.checked = res
  462. return e
  463. })
  464. if (res) {
  465. this.userInfoForm.deptIds = this.deptList.map(e => e.id)
  466. } else {
  467. this.userInfoForm.deptIds = []
  468. }
  469. console.log(this.userInfoForm.deptIds)
  470. },
  471. deptChose(res, item) {
  472. const tmp = this.deptList.find(ele => ele.id === item.id)
  473. if (tmp) {
  474. if (tmp.checked) {
  475. if (this.userInfoForm.deptIds.findIndex(e => e === tmp.id) === -1) {
  476. this.userInfoForm.deptIds.push(tmp.id)
  477. }
  478. } else {
  479. this.userInfoForm.deptIds = this.userInfoForm.deptIds.filter(
  480. ele => ele !== tmp.id
  481. )
  482. }
  483. }
  484. const count = this.deptList.filter(e => e.checked).length
  485. this.checkAll = count === this.deptList.length
  486. },
  487. roleSave() {
  488. const data = this.userInfoForm
  489. if (data.deptIds.length > 0) {
  490. data.deptIds = data.deptIds.join(',')
  491. } else {
  492. data.deptIds = this.form.deptId
  493. }
  494. data.isUpdate = false
  495. if (this.form.id) {
  496. data.userId = this.form.id
  497. this.$api.role.roleUpdate(data).then(res => {
  498. if (res.code === 200) {
  499. this.showEdit = false
  500. this.$message.success(res.msg)
  501. this.onLoad()
  502. } else {
  503. this.$message.error(res.msg)
  504. }
  505. })
  506. } else {
  507. this.$api.role.roleSave(data).then(res => {
  508. if (res.code === 200) {
  509. this.showEdit = false
  510. this.$message.success(res.msg)
  511. this.onLoad()
  512. } else {
  513. this.$message.error(res.msg)
  514. }
  515. })
  516. }
  517. },
  518. restPwd(row) {
  519. console.log(row)
  520. this.$prompt('', '更改 (' + row.name + ') 的密码', {
  521. inputPattern: /\w{6,16}/,
  522. inputErrorMessage: '密码长度在 6 到 16 个字符'
  523. }).then(({ value }) => {
  524. if (value.length === 0) {
  525. return
  526. }
  527. this.$api.role
  528. .restPwde({ userId: row.id, password: value })
  529. .then(res => {
  530. if (res.code === 200) {
  531. console.log(res)
  532. }
  533. })
  534. })
  535. },
  536. qrCodeSelect(deptId) {
  537. this.$api.role.invitation({ deptId, type: 4 }).then(res => {
  538. if (res.code === 200) {
  539. this.qrCodeText =
  540. 'https://dev.wutongresearch.club/apply?id=' +
  541. res.data.qrcodeId +
  542. '&deptId=' +
  543. deptId
  544. }
  545. })
  546. },
  547. closeCode() {
  548. this.qrCodeText = ''
  549. this.userInfoForm.deptId = ''
  550. }
  551. }
  552. }
  553. </script>
  554. <style scoped></style>