index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <template>
  2. <el-container>
  3. <el-main class="page-main">
  4. <el-card>
  5. <el-container>
  6. <el-aside class="tree-aside" :width="treeWidth">
  7. <tree title="Org" :fetch="this.$api.sysOrg.tree" :data-query="treeQuery" :call-back="getTreeDataCallBack" :click="treeClick" />
  8. </el-aside>
  9. <el-container>
  10. <el-header height="82">
  11. <el-form
  12. ref="searchForm"
  13. :model="dataQuery"
  14. :size="size"
  15. label-position="left"
  16. label-width="80px"
  17. >
  18. <el-row :gutter="20">
  19. <el-col :span="6">
  20. <el-form-item label="Mobile:" prop="mobile" class="notice-input" label-width="60px">
  21. <el-input v-model="dataQuery.login_id" placeholder="Please enter your account" clearable @keyup.enter.native="search" />
  22. </el-form-item>
  23. </el-col>
  24. <el-col :span="6">
  25. <el-form-item label="Name:" prop="name" class="notice-input" label-width="60px">
  26. <el-input v-model="dataQuery.name" placeholder="Please enter the name" clearable @keyup.enter.native="search" />
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="12" style="text-align: right">
  30. <el-form-item>
  31. <el-button type="primary" icon="el-icon-search" :size="size" @click="search">Search</el-button>
  32. <el-button icon="el-icon-refresh" :size="size" @click="resetFields">Reset</el-button>
  33. </el-form-item>
  34. </el-col>
  35. </el-row>
  36. <el-row>
  37. <el-button
  38. type="primary"
  39. icon="el-icon-plus"
  40. :size="size"
  41. @click="create"
  42. >New
  43. </el-button>
  44. <el-button
  45. v-if="checkPermission(['update_password'])"
  46. type="success"
  47. icon="el-icon-edit"
  48. :size="size"
  49. @click="updatePassword"
  50. >Change password
  51. </el-button>
  52. <el-button :size="size" @click="deleteBatch">Bulk Delete</el-button>
  53. </el-row>
  54. </el-form>
  55. </el-header>
  56. <el-main class="table-main">
  57. <sheet
  58. ref="qtable"
  59. :api="this.$api.sysUser.page"
  60. :columns="tableColumns"
  61. :data-query="dataQuery"
  62. :operates="operates"
  63. :float-type="'right'"
  64. :select-type="'selection'"
  65. header-name="searchForm"
  66. />
  67. </el-main>
  68. </el-container>
  69. </el-container>
  70. </el-card>
  71. </el-main>
  72. <el-dialog
  73. :title="dialogStatus==='create'?'New users':'Edit users'"
  74. :visible.sync="dialogVisible"
  75. width="50%"
  76. @close="dialogClose"
  77. >
  78. <el-form
  79. ref="tempForm"
  80. :size="size"
  81. :rules="rules"
  82. :model="temp"
  83. label-width="85px"
  84. >
  85. <el-form-item label="Name:" prop="name">
  86. <el-input v-model="temp.name" placeholder="Please enter the username" />
  87. </el-form-item>
  88. <el-form-item label="NickName:" prop="nickname">
  89. <el-input v-model="temp.login_id" placeholder="Please enter the nickname" />
  90. </el-form-item>
  91. <el-form-item v-if="dialogStatus === 'create'" label="Pwd:" prop="password">
  92. <el-input v-model="temp.password" placeholder=" Please enter your password" />
  93. </el-form-item>
  94. <el-form-item label="Org:">
  95. <el-select v-model="temp.org_id" style="width: 100%" placeholder=" Please select the org">
  96. <el-option
  97. v-for="item in orgs"
  98. :key="item.id"
  99. :label="item.name"
  100. :value="item.id"
  101. />
  102. </el-select>
  103. </el-form-item>
  104. <el-form-item label="Email:" prop="email">
  105. <el-input v-model="temp.email" placeholder="Please enter the mailbox" />
  106. </el-form-item>
  107. <el-form-item label="Mobile:" prop="mobile">
  108. <el-input v-model="temp.mobile" placeholder="Please enter your phone" />
  109. </el-form-item>
  110. <el-form-item v-if="dialogStatus=='update'" label="Role:" prop="type">
  111. <el-select v-model="temp.user_role" style="width: 100%" multiple placeholder="Please select the role">
  112. <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id" />
  113. </el-select>
  114. </el-form-item>
  115. <el-form-item label="Template:" prop="temp_id">
  116. <el-select v-model="temp.temp_id" style="width: 100%" placeholder="Please select the template" @change="tempChange">
  117. <el-option
  118. v-for="item in templs"
  119. :key="item.id"
  120. :label="item.name"
  121. :value="item.id"
  122. />
  123. </el-select>
  124. </el-form-item>
  125. <el-form-item
  126. v-for="(item, i) in temp_items"
  127. :key="item.id"
  128. :label="item.name + ':'"
  129. label-position="right"
  130. class="notice-input"
  131. :prop="item.id"
  132. >
  133. <el-input v-if="item.type == 0" v-model.number="temp_items[i].value" placeholder="Please ente" clearable />
  134. <el-input v-if="item.type == 2" v-model="temp_items[i].value" placeholder="Please ente" clearable />
  135. <!--<template v-if="item.type == 3">-->
  136. <!--<el-table :data="temp_items[i].value" class="tb-edit" style="width: 100%" highlight-current-row @row-click="handleCurrentChange">-->
  137. <!--<el-table-column v-for="col of JSON.parse(temp_items[i].content)" :prop="col.prop" :label="col.label" :width="col.width">-->
  138. <!--<template scope="scope">-->
  139. <!--<el-input v-model="temp_items[i].value[scope.$index][col.prop]" size="small" placeholder="请输入内容" @change="handleEdit(scope.$index, scope.row.prop)" /> <span>{{ temp_items[i].value[scope.$index][col.prop] }}</span>-->
  140. <!--</template>-->
  141. <!--</el-table-column>-->
  142. <!--<el-table-column label="操作">-->
  143. <!--<template scope="scope">-->
  144. <!--<el-button size="small" type="text" @click="handleDelete(scope.$index, i)">删除</el-button>-->
  145. <!--<el-button v-if="scope.$index == temp_items[i].value.length - 1" size="small" type="text" @click="addRow(i)">添加</el-button>-->
  146. <!--</template>-->
  147. <!--</el-table-column>-->
  148. <!--</el-table>-->
  149. <!--</template>-->
  150. </el-form-item>
  151. </el-form>
  152. <footer slot="footer" class="dialog-footer">
  153. <el-button :size="size" @click="dialogVisible = false">取 消</el-button>
  154. <el-button :size="size" type="primary" @click="dialogStatus==='create'?createData():updateData()">确 定
  155. </el-button>
  156. </footer>
  157. </el-dialog>
  158. <el-dialog title="Change password" :visible.sync="updatePswDialog" width="30%">
  159. <el-form ref="updatePswForm" :size="size" :rules="rules" :model="temp" label-width="85px">
  160. <el-form-item label="Mobile:" prop="mobile">
  161. <el-input v-model="temp.login_id" placeholder="Please enter the mobile" />
  162. </el-form-item>
  163. <el-form-item label="Name:" prop="name">
  164. <el-input v-model="temp.name" placeholder="Please enter the username" />
  165. </el-form-item>
  166. <el-form-item label="Pwd:" prop="password">
  167. <el-input v-model="temp.password" placeholder="Please enter the passowrd" />
  168. </el-form-item>
  169. </el-form>
  170. <footer slot="footer" class="dialog-footer">
  171. <el-button :size="size" @click="updatePswDialog = false">Cancel</el-button>
  172. <el-button :size="size" type="primary" @click="updatePws">confirm
  173. </el-button>
  174. </footer>
  175. </el-dialog>
  176. </el-container>
  177. </template>
  178. <script>
  179. import { mapGetters } from 'vuex'
  180. import { deepClone } from '@/utils/index'
  181. import checkPermission from '@/utils/permission'
  182. import Tree from '@/components/Tree'
  183. import Sheet from '@/components/Sheet'
  184. export default {
  185. name: 'User',
  186. components: {
  187. Tree,
  188. Sheet
  189. },
  190. data() {
  191. return {
  192. tableColumns: [
  193. { prop: 'name', label: 'Name', align: 'center', minWidth: 150, maxWidth: 180 },
  194. { prop: 'email', label: 'Email', align: 'center', minWidth: 150, maxWidth: 180 },
  195. { prop: 'mobile', label: 'Mobile', align: 'center', minWidth: 150, maxWidth: 180 },
  196. { prop: 'org_name', label: 'Org', align: 'center', minWidth: 150, maxWidth: 180 },
  197. { prop: 'role_name', label: 'Role', align: 'center', minWidth: 150, maxWidth: 180 },
  198. { prop: 'status', label: 'Status', align: 'center', minWidth: 150, maxWidth: 180 }
  199. ],
  200. operates: {
  201. list: [
  202. { label: 'Edit', show: true, type: 'text', method: (row) => { this.edit(row) } },
  203. { label: 'Del', show: true, type: 'text', method: (row) => { this.deleteData(row) } }
  204. ],
  205. width: 100,
  206. fixed: 'right'
  207. },
  208. dataQuery: {
  209. page: 1,
  210. rows: 10,
  211. login_id: '',
  212. name: '',
  213. cn_org_id: ''
  214. },
  215. rules: {
  216. name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
  217. login_id: [{ required: true, message: '请输入账号', trigger: 'blur' }],
  218. password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
  219. },
  220. treeQuery: { del_falg: 0 },
  221. temp: {
  222. id: undefined,
  223. login_id: '',
  224. name: '',
  225. password: '',
  226. email: '',
  227. mobile: '',
  228. type: 0,
  229. org_id: '',
  230. temp_value: '',
  231. temp_id: '',
  232. user_role: []
  233. },
  234. dataLoading: false,
  235. dialogStatus: '',
  236. dialogVisible: false,
  237. updatePswDialog: false,
  238. orgs: [],
  239. options: [],
  240. templs: [],
  241. temp_items: []
  242. }
  243. },
  244. computed: {
  245. inheritanceArray() {
  246. if (!this.temp.inheritance) {
  247. return []
  248. }
  249. let array = this.temp.inheritance.split('|').reverse()
  250. array = array.slice(1, array.length - 2)
  251. array.push(array[array.length - 1])
  252. return array
  253. },
  254. parent() {
  255. return this.inheritanceArray[this.inheritanceArray.length - 1]
  256. },
  257. ...mapGetters([
  258. 'size',
  259. 'minMainHeight',
  260. 'treeWidth'
  261. ])
  262. },
  263. mounted() {
  264. // 设置表头查询表单高度,使table高度自适应
  265. var height = this.$refs.searchForm.$el.offsetHeight
  266. this.$store.dispatch('app/pageTableHeaderHeight', { height: height })
  267. },
  268. destroyed() {
  269. // 页面注销,设置pageTableHeaderHeight为0
  270. this.$store.dispatch('app/pageTableHeaderHeight', { height: 0 })
  271. },
  272. created() {
  273. this.getOrgs()
  274. this.getRoles()
  275. this.FindUserTempl()
  276. },
  277. methods: {
  278. checkPermission,
  279. tempChange(temp_id) {
  280. this.getTempDetail(temp_id)
  281. },
  282. handleCurrentChange(row, event, column) {
  283. console.log(row, event, column, event.currentTarget)
  284. },
  285. handleEdit(index, row, col) {
  286. debugger
  287. },
  288. handleDelete(index, dataIndex) {
  289. this.temp_items[dataIndex].value.splice(index, 1)
  290. },
  291. addRow(dataIndex) {
  292. const obj = {}
  293. JSON.parse(this.temp_items[dataIndex].content).forEach(item => {
  294. obj[item.prop] = ''
  295. })
  296. this.temp_items[dataIndex].value.push(obj)
  297. },
  298. getTempDetail(temp_id) {
  299. this.$api.sysUserTemplate.page({ page: 1, rows: 100, 'temp_id': temp_id }).then(res => {
  300. this.temp_items = res.data.data
  301. var tempValue
  302. if (this.temp.temp_value !== '' && this.temp.temp_value !== undefined) {
  303. tempValue = JSON.parse(this.temp.temp_value)
  304. } else {
  305. tempValue = []
  306. }
  307. this.temp_items.forEach((item, i) => {
  308. tempValue.forEach(value => {
  309. if (item.id === value.id) {
  310. if (item.type === 3) {
  311. this.temp_items[i].value = value.value
  312. } else {
  313. this.temp_items[i].value = value.value
  314. }
  315. }
  316. })
  317. // 如果列表内容是空,默认添加一行空行
  318. if (item.type === 3 && this.temp_items[i].value === '') {
  319. var row = {}
  320. JSON.parse(this.temp_items[i].content).forEach(col => {
  321. row[col.prop] = '请输入'
  322. })
  323. this.temp_items[i].value = [row]
  324. }
  325. })
  326. })
  327. },
  328. FindUserTempl() {
  329. this.$api.sysUserTemplate.page({ page: 1, rows: 100 }).then(res => {
  330. if (res.code === 200) {
  331. this.templs = res.data.content
  332. }
  333. })
  334. },
  335. getOrgs() {
  336. this.$api.sysOrg.page({ 'page': 1, 'rows': 100 }).then(res => {
  337. this.orgs = res.data.data
  338. })
  339. },
  340. getRoles() {
  341. const pageData = { 'page': 1, 'rows': 100 }
  342. this.$api.sysRole.page(pageData).then(res => {
  343. this.options = res.data.data
  344. })
  345. },
  346. treeClick(node) {
  347. this.dataQuery.cn_org_id = node.id
  348. this.$refs.qtable.getData()
  349. },
  350. getTreeDataCallBack(tree) {},
  351. handleChange(value) {
  352. this.temp.parent = value[value.length - 1]
  353. },
  354. createData() {
  355. this.$refs['tempForm'].validate((valid) => {
  356. if (valid) {
  357. this.temp.temp_value = JSON.stringify(this.temp_items)
  358. this.$api.user.create(this.temp).then((res) => {
  359. this.dialogVisible = false
  360. if (res.code === 200) {
  361. this.$message({
  362. message: '创建成功',
  363. type: 'success'
  364. })
  365. this.$refs.qtable.getData()
  366. } else {
  367. this.$message({
  368. message: res.msg,
  369. type: 'error'
  370. })
  371. }
  372. })
  373. }
  374. })
  375. },
  376. updatePassword() {
  377. if (this.$refs.qtable.selectionData.length === 1) {
  378. this.temp = this.$refs.qtable.selectionData[0]
  379. this.temp.password = ''
  380. this.updatePswDialog = true
  381. } else {
  382. this.$message({
  383. message: '请选择一条记录',
  384. type: 'error'
  385. })
  386. }
  387. },
  388. updatePws() {
  389. this.$api.system.UpdatePassword(this.temp).then(res => {
  390. if (res.code === 200) {
  391. this.updatePswDialog = false
  392. this.$message({
  393. message: '修改成功',
  394. type: 'success'
  395. })
  396. } else {
  397. this.dialogVisible = false
  398. this.$message({
  399. message: '修改失败',
  400. type: 'error'
  401. })
  402. }
  403. })
  404. },
  405. updateData() {
  406. this.$refs['tempForm'].validate((valid) => {
  407. if (valid) {
  408. this.temp.temp_value = JSON.stringify(this.temp_items)
  409. this.$api.user.update(this.temp).then((res) => {
  410. if (res.code === 200) {
  411. this.dialogVisible = false
  412. this.$message({
  413. message: '修改成功',
  414. type: 'success'
  415. })
  416. this.$refs.qtable.getData()
  417. } else {
  418. this.dialogVisible = false
  419. this.$message({
  420. message: '修改失败',
  421. type: 'error'
  422. })
  423. }
  424. })
  425. }
  426. })
  427. },
  428. deleteData(row) {
  429. this.$confirm('确认删除这个用户吗?', '提示', {
  430. type: 'warning'
  431. }).then(() => {
  432. const data = [{ id: row.id }]
  433. this.$api.user.del(data).then((res) => {
  434. if (res.code === 200) {
  435. this.$refs.qtable.getData()
  436. this.$message({
  437. message: '删除成功',
  438. type: 'success'
  439. })
  440. } else {
  441. this.$message({
  442. message: '删除失败',
  443. type: 'error'
  444. })
  445. }
  446. })
  447. })
  448. },
  449. deleteBatch() {
  450. const ids = []
  451. this.$refs.qtable.multipleSelection.forEach(row => {
  452. ids.push({ id: row.id })
  453. })
  454. this.$confirm('确认批量删除选中数据吗?', '提示', {
  455. type: 'warning'
  456. }).then(() => {
  457. this.$api.user.del(ids).then(res => {
  458. if (res.code === 200) {
  459. this.$refs.qtable.getData()
  460. this.$message({
  461. message: '删除成功',
  462. type: 'success'
  463. })
  464. } else {
  465. this.$message({
  466. message: '删除失败',
  467. type: 'error'
  468. })
  469. }
  470. })
  471. }).catch(() => {
  472. })
  473. },
  474. search() {
  475. this.$refs.qtable.getData()
  476. },
  477. resetFields() {
  478. this.$refs['searchForm'].resetFields()
  479. this.$refs.qtable.getData()
  480. },
  481. dialogClose() {
  482. this.$refs['tempForm'].resetFields()
  483. },
  484. create() {
  485. this.dialogStatus = 'create'
  486. this.dialogVisible = true
  487. this.$nextTick(() => {
  488. this.$refs['tempForm'].clearValidate()
  489. })
  490. this.temp.temp_id = this.templs.filter((currentValue, index, arr) => {
  491. if (currentValue.default === 1) {
  492. return currentValue.id
  493. }
  494. })[0].id
  495. this.getTempDetail(this.temp.temp_id)
  496. },
  497. edit(row) {
  498. this.dialogStatus = 'update'
  499. this.dialogVisible = true
  500. this.$nextTick(() => {
  501. this.$refs['tempForm'].clearValidate()
  502. this.temp = deepClone(row)
  503. if (row.user_role === '') {
  504. this.temp.user_role = []
  505. } else {
  506. this.temp.user_role = row.user_role.split(',')
  507. }
  508. if (row.temp_id !== '') {
  509. this.getTempDetail(row.temp_id)
  510. } else {
  511. this.temp.temp_id = this.templs.filter((currentValue, index, arr) => {
  512. if (currentValue.type === 1) {
  513. return currentValue.id
  514. }
  515. })[0].id
  516. this.getTempDetail(this.temp.temp_id)
  517. }
  518. })
  519. }
  520. }
  521. }
  522. </script>
  523. <style>
  524. .tb-edit .el-input {
  525. display: none
  526. }
  527. .tb-edit .current-row .el-input {
  528. display: block
  529. }
  530. .tb-edit .current-row .el-input+span {
  531. display: none
  532. }
  533. </style>