index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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.mobile" 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. >{{ $t('common.create') }}
  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.nickname" 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.mobile" 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', formatter: 'sys_user_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. name: '',
  212. cn_org_id: ''
  213. },
  214. rules: {
  215. name: [{ required: true, message: '请输入账号名', trigger: 'blur' }],
  216. password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
  217. },
  218. treeQuery: { del_falg: 0 },
  219. temp: {
  220. id: undefined,
  221. name: '',
  222. password: '',
  223. email: '',
  224. mobile: '',
  225. type: 0,
  226. org_id: '',
  227. temp_value: '',
  228. temp_id: '',
  229. user_role: []
  230. },
  231. dataLoading: false,
  232. dialogStatus: '',
  233. dialogVisible: false,
  234. updatePswDialog: false,
  235. orgs: [],
  236. options: [],
  237. templs: [],
  238. temp_items: []
  239. }
  240. },
  241. computed: {
  242. inheritanceArray() {
  243. if (!this.temp.inheritance) {
  244. return []
  245. }
  246. let array = this.temp.inheritance.split('|').reverse()
  247. array = array.slice(1, array.length - 2)
  248. array.push(array[array.length - 1])
  249. return array
  250. },
  251. parent() {
  252. return this.inheritanceArray[this.inheritanceArray.length - 1]
  253. },
  254. ...mapGetters([
  255. 'size',
  256. 'minMainHeight',
  257. 'treeWidth'
  258. ])
  259. },
  260. mounted() {
  261. var height = this.$refs.searchForm.$el.offsetHeight
  262. this.$store.dispatch('app/pageTableHeaderHeight', { height: height })
  263. },
  264. destroyed() {
  265. this.$store.dispatch('app/pageTableHeaderHeight', { height: 0 })
  266. },
  267. created() {
  268. this.getOrgs()
  269. this.getRoles()
  270. this.FindUserTempl()
  271. },
  272. methods: {
  273. checkPermission,
  274. tempChange(temp_id) {
  275. this.getTempDetail(temp_id)
  276. },
  277. handleCurrentChange(row, event, column) {
  278. console.log(row, event, column, event.currentTarget)
  279. },
  280. handleEdit(index, row, col) {
  281. },
  282. handleDelete(index, dataIndex) {
  283. this.temp_items[dataIndex].value.splice(index, 1)
  284. },
  285. addRow(dataIndex) {
  286. const obj = {}
  287. JSON.parse(this.temp_items[dataIndex].content).forEach(item => {
  288. obj[item.prop] = ''
  289. })
  290. this.temp_items[dataIndex].value.push(obj)
  291. },
  292. getTempDetail(temp_id) {
  293. this.$api.sysUserTemplate.page({ page: 1, rows: 100, 'temp_id': temp_id }).then(res => {
  294. this.temp_items = res.data.data
  295. var tempValue
  296. if (this.temp.temp_value !== '' && this.temp.temp_value !== undefined) {
  297. tempValue = JSON.parse(this.temp.temp_value)
  298. } else {
  299. tempValue = []
  300. }
  301. this.temp_items.forEach((item, i) => {
  302. tempValue.forEach(value => {
  303. if (item.id === value.id) {
  304. if (item.type === 3) {
  305. this.temp_items[i].value = value.value
  306. } else {
  307. this.temp_items[i].value = value.value
  308. }
  309. }
  310. })
  311. // 如果列表内容是空,默认添加一行空行
  312. if (item.type === 3 && this.temp_items[i].value === '') {
  313. var row = {}
  314. JSON.parse(this.temp_items[i].content).forEach(col => {
  315. row[col.prop] = '请输入'
  316. })
  317. this.temp_items[i].value = [row]
  318. }
  319. })
  320. })
  321. },
  322. FindUserTempl() {
  323. this.$api.sysUserTemplate.page({ page: 1, rows: 100 }).then(res => {
  324. if (res.code === 200) {
  325. this.templs = res.data.content
  326. }
  327. })
  328. },
  329. getOrgs() {
  330. this.$api.sysOrg.page({ 'page': 1, 'rows': 100 }).then(res => {
  331. this.orgs = res.data.data
  332. })
  333. },
  334. getRoles() {
  335. const pageData = { 'page': 1, 'rows': 100 }
  336. this.$api.sysRole.page(pageData).then(res => {
  337. this.options = res.data.data
  338. })
  339. },
  340. treeClick(node) {
  341. this.dataQuery.cn_org_id = node.id
  342. this.$refs.qtable.getData()
  343. },
  344. getTreeDataCallBack(tree) {},
  345. handleChange(value) {
  346. this.temp.parent = value[value.length - 1]
  347. },
  348. createData() {
  349. this.$refs['tempForm'].validate((valid) => {
  350. if (valid) {
  351. this.temp.temp_value = JSON.stringify(this.temp_items)
  352. this.$api.sysUser.create(this.temp).then((res) => {
  353. if (res.code === 200) {
  354. this.$message({
  355. message: '创建成功',
  356. type: 'success'
  357. })
  358. this.$refs.qtable.getData()
  359. this.dialogVisible = false
  360. }
  361. })
  362. }
  363. })
  364. },
  365. updatePassword() {
  366. if (this.$refs.qtable.selectionData.length === 1) {
  367. this.temp = this.$refs.qtable.selectionData[0]
  368. this.temp.password = ''
  369. this.updatePswDialog = true
  370. } else {
  371. this.$message({
  372. message: '请选择一条记录',
  373. type: 'error'
  374. })
  375. }
  376. },
  377. updatePws() {
  378. this.$api.system.UpdatePassword(this.temp).then(res => {
  379. if (res.code === 200) {
  380. this.updatePswDialog = false
  381. this.$message({
  382. message: '修改成功',
  383. type: 'success'
  384. })
  385. this.dialogVisible = false
  386. } else {
  387. this.$message({
  388. message: '修改失败',
  389. type: 'error'
  390. })
  391. }
  392. })
  393. },
  394. updateData() {
  395. this.$refs['tempForm'].validate((valid) => {
  396. if (valid) {
  397. this.temp.temp_value = JSON.stringify(this.temp_items)
  398. this.$api.sysUser.update(this.temp).then((res) => {
  399. if (res.code === 200) {
  400. this.$message({
  401. message: '修改成功',
  402. type: 'success'
  403. })
  404. }
  405. this.dialogVisible = false
  406. }).catch(() => {})
  407. }
  408. })
  409. },
  410. deleteData(row) {
  411. this.$confirm('确认删除这个用户吗?', '提示', {
  412. type: 'warning'
  413. }).then(() => {
  414. const data = [{ id: row.id }]
  415. this.$api.sysUser.del(data).then((res) => {
  416. if (res.code === 200) {
  417. this.$refs.qtable.getData()
  418. this.$message({
  419. message: '删除成功',
  420. type: 'success'
  421. })
  422. }
  423. }).catch(() => {})
  424. })
  425. },
  426. deleteBatch() {
  427. const ids = []
  428. this.$refs.qtable.multipleSelection.forEach(row => {
  429. ids.push({ id: row.id })
  430. })
  431. this.$confirm('确认批量删除选中数据吗?', '提示', {
  432. type: 'warning'
  433. }).then(() => {
  434. this.$api.user.del(ids).then(res => {
  435. if (res.code === 200) {
  436. this.$refs.qtable.getData()
  437. this.$message({
  438. message: '删除成功',
  439. type: 'success'
  440. })
  441. }
  442. })
  443. }).catch(() => {})
  444. },
  445. search() {
  446. this.$refs.qtable.getData()
  447. },
  448. resetFields() {
  449. this.$refs['searchForm'].resetFields()
  450. this.dataQuery.cn_org_id = ''
  451. this.$refs.qtable.getData()
  452. },
  453. dialogClose() {
  454. this.$refs['tempForm'].resetFields()
  455. },
  456. create() {
  457. this.dialogStatus = 'create'
  458. this.dialogVisible = true
  459. this.$nextTick(() => {
  460. this.$refs['tempForm'].clearValidate()
  461. })
  462. this.temp.temp_id = this.templs.filter((currentValue, index, arr) => {
  463. if (currentValue.default === 1) {
  464. return currentValue.id
  465. }
  466. })[0].id
  467. this.getTempDetail(this.temp.temp_id)
  468. },
  469. edit(row) {
  470. this.dialogStatus = 'update'
  471. this.dialogVisible = true
  472. this.$nextTick(() => {
  473. this.$refs['tempForm'].clearValidate()
  474. this.temp = deepClone(row)
  475. if (row.user_role === '') {
  476. this.temp.user_role = []
  477. } else {
  478. this.temp.user_role = row.user_role.split(',')
  479. }
  480. if (row.temp_id !== '') {
  481. this.getTempDetail(row.temp_id)
  482. } else {
  483. this.temp.temp_id = this.templs.filter((currentValue, index, arr) => {
  484. if (currentValue.type === 1) {
  485. return currentValue.id
  486. }
  487. })[0].id
  488. this.getTempDetail(this.temp.temp_id)
  489. }
  490. })
  491. }
  492. }
  493. }
  494. </script>
  495. <style>
  496. .tb-edit .el-input {
  497. display: none
  498. }
  499. .tb-edit .current-row .el-input {
  500. display: block
  501. }
  502. .tb-edit .current-row .el-input+span {
  503. display: none
  504. }
  505. </style>