MasterMobileRole.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <div>
  3. <el-button type="success" style="margin-bottom: 15px;" class="el-icon-document-add" @click="openAddRole">
  4. 添加角色
  5. </el-button>
  6. <el-table
  7. v-loading="viewListLoading"
  8. :data="tableData"
  9. style="width: 100%"
  10. :size="tableSize"
  11. :max-height="maxHeight"
  12. :row-class-name="tableRowClassName"
  13. :header-cell-style="{background:'#eef1f6',color:'#606266'}">
  14. <el-table-column
  15. fixed
  16. prop="id"
  17. label="序号"
  18. min-width="50">
  19. </el-table-column>
  20. <el-table-column
  21. prop="name"
  22. label="名称"
  23. min-width="120">
  24. </el-table-column>
  25. <el-table-column
  26. prop="createTime"
  27. label="创建时间"
  28. min-width="180">
  29. </el-table-column>
  30. <el-table-column
  31. prop="modifyTime"
  32. label="修改时间"
  33. min-width="180">
  34. </el-table-column>
  35. <el-table-column
  36. fixed="right"
  37. label="操作"
  38. min-width ="120">
  39. <template slot-scope="scope">
  40. <el-tooltip content="编辑" placement="left-start" effect="light">
  41. <el-button
  42. @click.native.prevent="editRow(scope.$index, tableData)"
  43. icon="el-icon-edit"
  44. size="mini"
  45. type="primary">
  46. </el-button>
  47. </el-tooltip>
  48. <el-tooltip content="删除" placement="top-end" effect="light">
  49. <el-button
  50. @click.native.prevent="deleteRow(scope.$index, tableData)"
  51. icon="el-icon-delete"
  52. size="mini"
  53. type="danger">
  54. </el-button>
  55. </el-tooltip>
  56. </template>
  57. </el-table-column>
  58. </el-table>
  59. <div class="pagination" style="text-align: right;">
  60. <el-pagination
  61. @size-change="handleSizeChange"
  62. @current-change="handleCurrentChange"
  63. :page-sizes="[10, 15, 20]"
  64. :page-size="pagination.pageSize"
  65. layout="total, sizes, prev, pager, next, jumper"
  66. :total="pagination.total">
  67. </el-pagination>
  68. </div>
  69. <!-- 弹出框form -->
  70. <el-dialog title="角色" :visible.sync="dialogFormVisible" @close="closeDialog" fullscreen>
  71. <el-form :size="addFormSize" label-position="left">
  72. <el-form-item label="序号" :size="addFormSize" v-show="addForm.id" :label-width="formLabelWidth">
  73. <el-input disabled v-model="addForm.id"></el-input>
  74. </el-form-item>
  75. <el-form-item label="名称" :size="addFormSize" :label-width="formLabelWidth">
  76. <el-input v-model="addForm.name" autocomplete="off"></el-input>
  77. </el-form-item>
  78. <el-table :data="gridData"
  79. :max-height="maxHeight"
  80. :loading="loading"
  81. element-loading-text="加载中"
  82. element-loading-spinner="el-icon-loading"
  83. element-loading-background="rgba(0, 0, 0, 0.8)"
  84. style="width: 100%"
  85. ref="moduleTable">
  86. <el-table-column type="selection" width="55"></el-table-column>
  87. <el-table-column property="moduleId" label="模块编码" width="100"></el-table-column>
  88. <el-table-column property="moduleName" label="模块名称" width="200"></el-table-column>
  89. <el-table-column property="moduleType" label="模块类型" width="100"></el-table-column>
  90. <el-table-column property="isQuery" label="查看">
  91. <template slot-scope="scope">
  92. <el-switch
  93. v-model="gridData[scope.$index].isQuery"
  94. @change="changeTableState('query', scope.$index, gridData)"
  95. active-color="#13ce66"
  96. inactive-color="#ff4949">
  97. </el-switch>
  98. </template>
  99. </el-table-column>
  100. <el-table-column property="isEdit" label="编辑">
  101. <template slot-scope="scope">
  102. <el-switch
  103. v-model="gridData[scope.$index].isEdit"
  104. :disabled="gridData[scope.$index].baseModuleType === 0"
  105. @change="changeTableState('edit', scope.$index, gridData)"
  106. active-color="#13ce66"
  107. inactive-color="#ff4949">
  108. </el-switch>
  109. </template>
  110. </el-table-column>
  111. </el-table>
  112. <el-form-item>
  113. </el-form-item>
  114. </el-form>
  115. <div slot="footer" class="dialog-footer">
  116. <el-button @click="dialogCancel">取 消</el-button>
  117. <el-button type="primary" @click="addOrEditForm(dialogFormButton)">确 定</el-button>
  118. </div>
  119. </el-dialog>
  120. </div>
  121. </template>
  122. <script>
  123. export default {
  124. name: "MasterMobileRole",
  125. methods: {
  126. sendRequest(pageNum) {
  127. this.viewListLoading = true;
  128. //发送查询角色的请求方法
  129. let reqPageNum = pageNum ? pageNum : this.pagination.pageNum;
  130. this.getRequest('/master/mobile-role/?pageSize=' + this.pagination.pageSize
  131. + '&pageNum=' + reqPageNum).then((resp)=> {
  132. if(resp) {
  133. this.tableData = resp.data.records;
  134. this.pagination.total = resp.data.total;
  135. }
  136. this.viewListLoading = false;
  137. }, () => {this.viewListLoading = false;})
  138. },
  139. openAddRole() {
  140. //点击添加按钮时事件
  141. this.dialogFormVisible = true;
  142. this.getModuleList();
  143. },
  144. addOrEditForm(type) {
  145. //处理添加或编辑确定的方法
  146. if(type) {
  147. this.addForm.moduleList = this.$refs.moduleTable.selection;
  148. this.postRequest('/master/mobile-role/', this.addForm).then(resp => {
  149. if(resp) {
  150. this.closeDialog();
  151. this.sendRequest(1);
  152. }
  153. })
  154. } else {
  155. this.addForm.moduleList = this.$refs.moduleTable.selection;
  156. this.putRequest('/master/mobile-role/', this.addForm).then(resp => {
  157. this.sendRequest()
  158. })
  159. }
  160. },
  161. editRow(index, rows) {
  162. //点击编辑按钮事件
  163. let row = rows[index];
  164. this.addForm.id = row.id;
  165. this.addForm.name = row.name;
  166. this.dialogFormVisible = true;
  167. this.dialogFormButton = false;
  168. this.getModuleList(row);
  169. },
  170. deleteRow(index, rows) {
  171. //点击删除按钮事件
  172. let row = rows[index];
  173. let promptMessages = ['确认删除信息:', `序号: ${row.id}`, `名称: ${row.name}`]
  174. const newPromptMessages = []
  175. const h = this.$createElement
  176. for (const i in promptMessages) {
  177. newPromptMessages.push(h('p', null, promptMessages[i]))
  178. }
  179. //删除角色
  180. this.$confirm('提示', {
  181. message: h('div', null, newPromptMessages),
  182. confirmButtonText: '确定',
  183. cancelButtonText: '取消',
  184. center: true,
  185. type: 'warning'
  186. }).then(() => {
  187. //发送删除请求
  188. this.deleteRequest('/master/mobile-role/' + row.id).then(resp => {
  189. this.sendRequest();
  190. });
  191. }).catch(() => {
  192. console.log('取消删除')
  193. })
  194. },
  195. changeTableState(type, index, rows) {
  196. //switch改变状态时触发事件
  197. let row = rows[index];
  198. // console.log(row);
  199. },
  200. handleSizeChange(val) {
  201. //改变每页显示多少条记录触发事件
  202. this.pagination.pageSize = val;
  203. this.sendRequest();
  204. },
  205. handleCurrentChange(val) {
  206. //改变当前页码时触发事件
  207. this.pagination.pageNum = val;
  208. this.sendRequest();
  209. },
  210. tableRowClassName({row, rowIndex}) {
  211. //隔行背景色变色处理
  212. if (rowIndex % 2 === 1) {
  213. return 'row-bg-color';
  214. } else {
  215. return ''
  216. }
  217. },
  218. clearForm() {
  219. //清空提交表单内容
  220. this.addForm.id = '';
  221. this.addForm.name = '';
  222. this.addForm.moduleList = [];
  223. this.$refs.moduleTable.clearSelection();
  224. this.gridData = [];
  225. },
  226. dialogCancel() {
  227. //点击取消按钮事件
  228. this.dialogFormVisible = false;
  229. this.dialogFormButton = true;
  230. this.clearForm();
  231. },
  232. closeDialog() {
  233. //关闭弹框时事件
  234. this.dialogCancel();
  235. },
  236. getModuleList(row) {
  237. this.loading = true;
  238. this.getRequest('/common-query/mobile/module').then(resp => {
  239. if(resp) {
  240. resp.forEach((value, index, array) => {
  241. value.mmId = value.id;
  242. value.isQuery = true;
  243. value.isEdit = value.baseModuleType != 0 ? true : false;
  244. })
  245. this.gridData = resp;
  246. if(row) {
  247. this.getRequest('/master/mobile-role/info/' + row.id).then(resp => {
  248. if(resp) {
  249. let moduleList = resp.data.moduleList
  250. if(moduleList && moduleList.length > 0) {
  251. if(moduleList && this.gridData.length > 0) {
  252. this.gridData.forEach((value, index, array) => {
  253. moduleList.find((m, i, o) => {
  254. if(m.mmId == value.mmId) {
  255. value.isQuery = m.isQuery;
  256. value.isEdit = m.isEdit;
  257. this.$refs.moduleTable.toggleRowSelection(value,true);
  258. }
  259. })
  260. })
  261. }
  262. }
  263. }
  264. })
  265. }
  266. this.loading = false;
  267. }
  268. })
  269. }
  270. },
  271. data() {
  272. return {
  273. viewListLoading: true,
  274. loading: true,
  275. tableSize: 'medium',
  276. maxHeight: 500,
  277. tableData: [],
  278. pagination: {
  279. pageSize: 10,
  280. pageNum: 1,
  281. total: 0
  282. },
  283. dialogFormVisible: false,
  284. addForm: {
  285. id: '',
  286. name: '',
  287. moduleList: []
  288. },
  289. gridData: [],
  290. formLabelWidth: '120px',
  291. addFormSize: 'small',
  292. dialogFormButton: true
  293. }
  294. },
  295. computed: {
  296. isDisabled() {
  297. //判断点击按钮触发的是添加还是编辑时事件
  298. let id = this.addForm.id;
  299. if(id !== undefined && id !== null && id !== '')
  300. return true;
  301. return false;
  302. }
  303. },
  304. mounted() {
  305. //vue组件加载完成后触发自动查询
  306. this.sendRequest();
  307. }
  308. }
  309. </script>
  310. <style>
  311. .el-table .row-bg-color {
  312. background: #eef1f6;
  313. }
  314. </style>