RolePushBtnModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <div ref="container">
  3. <a-modal
  4. :title="title"
  5. :width="width"
  6. :visible="visible"
  7. :confirmLoading="confirmLoading"
  8. :getContainer="() => $refs.container"
  9. :maskStyle="{ top: '93px', left: '154px' }"
  10. :wrapClassName="wrapClassNameInfo()"
  11. :mask="isDesktop()"
  12. :maskClosable="false"
  13. @ok="handleOk"
  14. @cancel="handleCancel"
  15. cancelText="取消"
  16. okText="保存"
  17. style="top: 5%; height: 95%"
  18. >
  19. <a-spin :spinning="confirmLoading">
  20. <div class="table-page-search-wrapper">
  21. <!-- 按钮区域 -->
  22. <a-form layout="inline">
  23. <a-row :gutter="24">
  24. <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
  25. <a-col :md="12" :sm="24">
  26. <a-button @click="toggleChecked">
  27. {{ !checked ? '全选' : '全取消' }}
  28. </a-button>
  29. <a-button @click="editToggleChecked" style="margin-left: 8px">
  30. {{ !editChecked ? '全选-编辑' : '全取消-编辑' }}
  31. </a-button>
  32. <a-button @click="auditToggleChecked" style="margin-left: 8px">
  33. {{ !auditChecked ? '全选-审核' : '全取消-审核' }}
  34. </a-button>
  35. <a-button @click="unAuditToggleChecked" style="margin-left: 8px">
  36. {{ !unAuditChecked ? '全选-反审核' : '全取消-反审核' }}
  37. </a-button>
  38. <a-button @click="exportToggleChecked" style="margin-left: 8px">
  39. {{ !exportChecked ? '全选-导出' : '全取消-导出' }}
  40. </a-button>
  41. </a-col>
  42. </span>
  43. </a-row>
  44. </a-form>
  45. </div>
  46. <!-- table区域-begin -->
  47. <div>
  48. <a-table
  49. ref="table"
  50. size="middle"
  51. bordered
  52. rowKey="id"
  53. :pagination="false"
  54. :columns="columns"
  55. :dataSource="dataSource"
  56. :loading="loading"
  57. >
  58. <span slot="action" slot-scope="text, record, index">
  59. <a-checkbox
  60. v-if="record.pushBtn.indexOf(1) > -1"
  61. value="1"
  62. :checked="record.btnStr ? record.btnStr.indexOf(1) > -1 : false"
  63. @change="onChange(record, '1', index)"
  64. >编辑</a-checkbox
  65. >
  66. <a-checkbox
  67. v-if="record.pushBtn.indexOf(2) > -1"
  68. value="2"
  69. :checked="record.btnStr ? record.btnStr.indexOf(2) > -1 : false"
  70. @change="onChange(record, '2', index)"
  71. >审核</a-checkbox
  72. >
  73. <a-checkbox
  74. v-if="record.pushBtn.indexOf(7) > -1"
  75. value="7"
  76. :checked="record.btnStr ? record.btnStr.indexOf(7) > -1 : false"
  77. @change="onChange(record, '7', index)"
  78. >反审核</a-checkbox
  79. >
  80. <a-checkbox
  81. v-if="record.pushBtn.indexOf(3) > -1"
  82. value="3"
  83. :checked="record.btnStr ? record.btnStr.indexOf(3) > -1 : false"
  84. @change="onChange(record, '3', index)"
  85. >导出</a-checkbox
  86. >
  87. <a-checkbox
  88. v-if="record.pushBtn.indexOf(4) > -1"
  89. value="4"
  90. :checked="record.btnStr ? record.btnStr.indexOf(4) > -1 : false"
  91. @change="onChange(record, '4', index)"
  92. >启用禁用</a-checkbox
  93. >
  94. <a-checkbox
  95. v-if="record.pushBtn.indexOf(5) > -1"
  96. value="5"
  97. :checked="record.btnStr ? record.btnStr.indexOf(5) > -1 : false"
  98. @change="onChange(record, '5', index)"
  99. >打印</a-checkbox
  100. >
  101. <a-checkbox
  102. v-if="record.pushBtn.indexOf(6) > -1"
  103. value="6"
  104. :checked="record.btnStr ? record.btnStr.indexOf(6) > -1 : false"
  105. @change="onChange(record, '6', index)"
  106. >作废</a-checkbox
  107. >
  108. </span>
  109. </a-table>
  110. </div>
  111. </a-spin>
  112. </a-modal>
  113. </div>
  114. </template>
  115. <script>
  116. import pick from 'lodash.pick'
  117. import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  118. import { getAction } from '@/api/manage'
  119. import { updateBtnStrByRoleId } from '@/api/api'
  120. import { removeByVal } from '@/utils/util'
  121. import { mixinDevice } from '@/utils/mixin'
  122. export default {
  123. name: 'RolePushBtnModal',
  124. mixins: [JeecgListMixin, mixinDevice],
  125. data() {
  126. return {
  127. title: '操作',
  128. width: '800px',
  129. visible: false,
  130. model: {},
  131. checked: false,
  132. editChecked: false,
  133. auditChecked: false,
  134. unAuditChecked: false,
  135. exportChecked: false,
  136. disableMixinCreated: true,
  137. confirmLoading: false,
  138. form: this.$form.createForm(this),
  139. /* 数据源 */
  140. dataSource: [],
  141. // 表头
  142. columns: [
  143. {
  144. title: '#',
  145. dataIndex: '',
  146. key: 'rowIndex',
  147. width: 40,
  148. align: 'center',
  149. customRender: function (t, r, index) {
  150. return parseInt(index) + 1
  151. },
  152. },
  153. {
  154. title: '名称',
  155. align: 'center',
  156. dataIndex: 'name',
  157. },
  158. {
  159. title: '按钮列表',
  160. dataIndex: 'action',
  161. align: 'center',
  162. scopedSlots: { customRender: 'action' },
  163. },
  164. ],
  165. url: {
  166. list: '/function/findRoleFunctionsById',
  167. },
  168. }
  169. },
  170. created() {},
  171. methods: {
  172. edit(roleId) {
  173. this.form.resetFields()
  174. this.model.id = roleId
  175. this.visible = true
  176. if (roleId) {
  177. getAction(this.url.list, { roleId: roleId }).then((res) => {
  178. if (res.code === 200) {
  179. this.dataSource = res.data.rows
  180. this.ipagination.total = res.data.total
  181. } else if (res.code === 400) {
  182. this.dataSource = []
  183. this.ipagination.total = 0
  184. } else if (res.code === 500) {
  185. this.$message.warning(res.data)
  186. }
  187. this.loading = false
  188. })
  189. }
  190. },
  191. close() {
  192. this.$emit('close')
  193. this.visible = false
  194. },
  195. handleCancel() {
  196. this.close()
  197. },
  198. handleOk() {
  199. const that = this
  200. // 触发表单验证
  201. this.form.validateFields((err, values) => {
  202. if (!err) {
  203. that.confirmLoading = true
  204. let funArray = this.dataSource
  205. let bindArr = []
  206. let btnStr = ''
  207. for (let item of funArray) {
  208. if (item.btnStr !== undefined && item.btnStr !== '' && item.btnStr !== 'null' && item.btnStr !== null) {
  209. let bindJSON = {}
  210. bindJSON.funId = item.id
  211. bindJSON.btnStr = item.btnStr
  212. bindArr.push(bindJSON)
  213. }
  214. }
  215. if (bindArr.length) {
  216. btnStr = JSON.stringify(bindArr)
  217. }
  218. let obj = updateBtnStrByRoleId({ roleId: this.model.id, btnStr: btnStr })
  219. obj
  220. .then((res) => {
  221. if (res.code === 200) {
  222. that.$emit('ok')
  223. } else {
  224. that.$message.warning(res.data)
  225. }
  226. })
  227. .finally(() => {
  228. that.confirmLoading = false
  229. that.close()
  230. })
  231. }
  232. })
  233. },
  234. toggleChecked() {
  235. this.checked = !this.checked
  236. let funArray = this.dataSource.slice()
  237. if (this.checked) {
  238. for (let item of funArray) {
  239. item.btnStr = item.pushBtn
  240. }
  241. } else {
  242. for (let item of funArray) {
  243. item.btnStr = ''
  244. }
  245. }
  246. this.dataSource = funArray
  247. },
  248. editToggleChecked() {
  249. this.editChecked = !this.editChecked
  250. let funArray = this.dataSource.slice()
  251. if (this.editChecked) {
  252. for (let item of funArray) {
  253. item.btnStr = this.parseArrByParam(1, item.btnStr, 1)
  254. }
  255. } else {
  256. for (let item of funArray) {
  257. item.btnStr = this.parseArrByParam(1, item.btnStr, 0)
  258. }
  259. }
  260. this.dataSource = funArray
  261. },
  262. auditToggleChecked() {
  263. this.auditChecked = !this.auditChecked
  264. let funArray = this.dataSource.slice()
  265. if (this.auditChecked) {
  266. for (let item of funArray) {
  267. item.btnStr = this.parseArrByParam(2, item.btnStr, 1)
  268. }
  269. } else {
  270. for (let item of funArray) {
  271. item.btnStr = this.parseArrByParam(2, item.btnStr, 0)
  272. }
  273. }
  274. this.dataSource = funArray
  275. },
  276. unAuditToggleChecked() {
  277. this.unAuditChecked = !this.unAuditChecked
  278. let funArray = this.dataSource.slice()
  279. if (this.unAuditChecked) {
  280. for (let item of funArray) {
  281. item.btnStr = this.parseArrByParam(7, item.btnStr, 1)
  282. }
  283. } else {
  284. for (let item of funArray) {
  285. item.btnStr = this.parseArrByParam(7, item.btnStr, 0)
  286. }
  287. }
  288. this.dataSource = funArray
  289. },
  290. exportToggleChecked() {
  291. this.exportChecked = !this.exportChecked
  292. let funArray = this.dataSource.slice()
  293. if (this.exportChecked) {
  294. for (let item of funArray) {
  295. item.btnStr = this.parseArrByParam(3, item.btnStr, 1)
  296. }
  297. } else {
  298. for (let item of funArray) {
  299. item.btnStr = this.parseArrByParam(3, item.btnStr, 0)
  300. }
  301. }
  302. this.dataSource = funArray
  303. },
  304. /**
  305. * 格式转换,控制按钮的显示或隐藏
  306. * @param param
  307. * @param btnStr
  308. * @param type
  309. * @returns {string}
  310. */
  311. parseArrByParam(param, btnStr, type) {
  312. if (type) {
  313. btnStr = btnStr + ','
  314. if (btnStr.indexOf(param + ',') === -1) {
  315. btnStr = btnStr + param + ','
  316. }
  317. } else {
  318. btnStr = btnStr + ','
  319. if (btnStr.indexOf(param + ',') > -1) {
  320. btnStr = btnStr.replace(param + ',', '')
  321. }
  322. }
  323. if (btnStr) {
  324. btnStr = btnStr.replace('null', '')
  325. btnStr = btnStr.substring(0, btnStr.length - 1)
  326. if (btnStr.substring(0, 1) === ',') {
  327. btnStr = btnStr.substring(1)
  328. }
  329. }
  330. return btnStr
  331. },
  332. onChange(record, value, index) {
  333. let funArray = this.dataSource
  334. for (let item of funArray) {
  335. if (item.id === record.id) {
  336. let btnStr = record.btnStr
  337. if (btnStr) {
  338. let btnArr = btnStr.split(',')
  339. if (btnStr.indexOf(value) > -1) {
  340. //去掉勾选
  341. removeByVal(btnArr, value)
  342. item.btnStr = btnArr.join()
  343. this.$set(this.dataSource, index, item)
  344. } else {
  345. //勾选
  346. btnArr.push(value)
  347. item.btnStr = btnArr.join()
  348. this.$set(this.dataSource, index, item)
  349. }
  350. } else {
  351. let btnArr = []
  352. //勾选
  353. btnArr.push(value)
  354. item.btnStr = btnArr.join()
  355. this.$set(this.dataSource, index, item)
  356. }
  357. }
  358. }
  359. },
  360. },
  361. }
  362. </script>
  363. <style scoped></style>