manage.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. @close="closeCode"
  43. >
  44. <div>
  45. <el-form
  46. ref="form"
  47. :model="userInfoForm"
  48. :rules="rules"
  49. class="mt-20"
  50. label-width="100px"
  51. >
  52. <div class="flex flex-center">
  53. <el-form-item class="full-width" label="登录账号" prop="name">
  54. <el-input
  55. v-model="userInfoForm.account"
  56. clearable
  57. placeholder="输入用户名称"
  58. />
  59. </el-form-item>
  60. <el-form-item
  61. class="full-width mr-20"
  62. label="真实姓名"
  63. :rules="rules"
  64. prop="realName"
  65. >
  66. <el-input
  67. v-model="userInfoForm.realName"
  68. clearable
  69. placeholder="输入真实姓名"
  70. >
  71. </el-input>
  72. </el-form-item>
  73. </div>
  74. <div class="flex flex-center">
  75. <el-form-item label="手机号码" class="full-width" prop="phone">
  76. <el-input
  77. v-model="userInfoForm.phone"
  78. clearable
  79. placeholder="输入手机号码"
  80. >
  81. </el-input>
  82. </el-form-item>
  83. <el-form-item
  84. class="full-width mr-20"
  85. label="登陆密码"
  86. prop="password"
  87. >
  88. <el-input
  89. v-model="userInfoForm.password"
  90. :disabled="form.type !== 'add'"
  91. clearable
  92. :placeholder="form.type !== 'add' ? '******' : '输入登陆密码'"
  93. >
  94. </el-input>
  95. </el-form-item>
  96. </div>
  97. <div class="flex flex-align-center">
  98. <span class="ml-20 bold">部门选择</span>
  99. <el-form-item class="flex">
  100. <el-select
  101. class="mt-20"
  102. v-model="userInfoForm.deptId"
  103. style="width: 250px; margin-left: -75px"
  104. placeholder="选择用户所属部门"
  105. >
  106. <el-option
  107. v-for="item in deptList"
  108. :key="item.id"
  109. :label="item.deptName"
  110. :value="item.id"
  111. />
  112. </el-select>
  113. </el-form-item>
  114. </div>
  115. <div class="flex flex-col mt-10">
  116. <span class="ml-20 bold">职务选择</span>
  117. <el-form-item class="flex flex-wrap">
  118. <div class="flex flex-center padding pointer">
  119. <el-radio-group size="large" v-model="userInfoForm.roleIds">
  120. <el-radio v-for="item in jobs" :key="item.id" :label="item.id"
  121. >{{ item.roleName }}
  122. </el-radio>
  123. </el-radio-group>
  124. </div>
  125. </el-form-item>
  126. </div>
  127. <div class="flex flex-col" style="margin-top: -10px">
  128. <div class="flex flex-align-center">
  129. <span class="bold ml-20">管理股室</span>
  130. <el-checkbox
  131. size="large"
  132. style="margin-left: 33px"
  133. v-model="checkAll"
  134. @change="choseAll"
  135. >全选
  136. </el-checkbox>
  137. </div>
  138. <el-form-item class="flex flex-wrap">
  139. <div class="flex flex-center padding pointer">
  140. <el-checkbox
  141. v-model="item.checked"
  142. :label="item.id"
  143. size="large"
  144. v-for="item in deptList"
  145. :key="item.id"
  146. @change="deptChose($event, item)"
  147. >
  148. {{ item.deptName }}
  149. </el-checkbox>
  150. </div>
  151. </el-form-item>
  152. </div>
  153. <div class="flex flex-center">
  154. <base-button
  155. title="取消"
  156. type="0"
  157. icon="Close"
  158. @click="showEdit = false"
  159. />
  160. <base-button
  161. class="ml-10"
  162. title="保存"
  163. icon="Check"
  164. @click="roleSave"
  165. />
  166. </div>
  167. </el-form>
  168. </div>
  169. </el-dialog>
  170. <el-dialog
  171. v-model="showQrCode"
  172. title="邀请二维码"
  173. width="500"
  174. @close="closeCode"
  175. >
  176. <div>
  177. <div class="full-width flex flex-center">
  178. <span class="mr-20">用户所属部门</span>
  179. <el-select
  180. v-model="userInfoForm.deptId"
  181. placeholder="选择用户所属部门"
  182. @change="qrCodeSelect"
  183. >
  184. <el-option
  185. v-for="item in deptList"
  186. :key="item.id"
  187. :label="item.deptName"
  188. :value="item.id"
  189. />
  190. </el-select>
  191. </div>
  192. <div v-if="qrCodeText.length > 0" class="flex flex-center flex-col">
  193. <vue-qr
  194. class="mt-10"
  195. :currentLevel="1"
  196. :logoCornerRadius="4"
  197. :logoScale="0.25"
  198. :logoSrc="logoSrc"
  199. :text="qrCodeText"
  200. size="220"
  201. />
  202. <span>- 复制二维码图片,通过微信发送邀请 -</span>
  203. </div>
  204. <el-empty v-else description="暂无数据" />
  205. </div>
  206. </el-dialog>
  207. </basic-container>
  208. </template>
  209. <route>
  210. {
  211. name: '用户管理',
  212. meta: { 'back':true,'showMsg' : "如果手机号为用户微信绑定的手机号时,微信小程序将自动登录,并同步信息!"}
  213. }
  214. </route>
  215. <script>
  216. import BasicContainer from '@/components/basic-container/main.vue'
  217. import { useStore } from '@/store/user.js'
  218. import baseButton from '@/components/base-button.vue'
  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. account: '',
  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.account = this.form.account
  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. if (this.deptList.filter(e => e.checked).length === 0) {
  489. this.$message.error('请选择管理股室')
  490. return
  491. }
  492. if (this.userInfoForm.roleIds.length === 0) {
  493. this.$message.error('请选择职务')
  494. return
  495. }
  496. const data = this.userInfoForm
  497. if (data.deptIds.length > 0) {
  498. data.deptIds = data.deptIds.join(',')
  499. } else {
  500. data.deptIds = this.form.deptId
  501. }
  502. data.isUpdate = false
  503. if (this.form.id) {
  504. data.userId = this.form.id
  505. this.$api.role.roleUpdate(data).then(res => {
  506. if (res.code === 200) {
  507. this.showEdit = false
  508. this.$message.success(res.msg)
  509. this.onLoad()
  510. } else {
  511. this.$message.error(res.msg)
  512. }
  513. })
  514. } else {
  515. this.$api.role.roleSave(data).then(res => {
  516. if (res.code === 200) {
  517. this.showEdit = false
  518. this.$message.success(res.msg)
  519. this.onLoad()
  520. } else {
  521. this.$message.error(res.msg)
  522. }
  523. })
  524. }
  525. },
  526. restPwd(row) {
  527. console.log(row)
  528. this.$prompt('', '更改 (' + row.name + ') 的密码', {
  529. inputPattern: /\w{6,16}/,
  530. inputErrorMessage: '密码长度在 6 到 16 个字符'
  531. }).then(({ value }) => {
  532. if (value.length === 0) {
  533. return
  534. }
  535. this.$api.role
  536. .restPwde({ userId: row.id, password: value })
  537. .then(res => {
  538. if (res.code === 200) {
  539. console.log(res)
  540. }
  541. })
  542. })
  543. },
  544. qrCodeSelect(deptId) {
  545. this.$api.role.invitation({ deptId, type: 4 }).then(res => {
  546. if (res.code === 200) {
  547. this.qrCodeText =
  548. 'https://dev.wutongresearch.club/apply?id=' +
  549. res.data.qrcodeId +
  550. '&deptId=' +
  551. deptId +
  552. '&roleName=股室'
  553. }
  554. })
  555. },
  556. closeCode() {
  557. this.userInfoForm = {
  558. name: '',
  559. realName: '',
  560. phone: '',
  561. password: '',
  562. roleIds: '',
  563. deptIds: [],
  564. deptId: ''
  565. }
  566. this.deptList.map(e => (e.checked = false))
  567. this.qrCodeText = ''
  568. }
  569. }
  570. }
  571. </script>
  572. <style scoped></style>