role.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div v-loading="loading">
  3. <div class="white-box">
  4. <div class="filter-box">
  5. <filter-user
  6. :filter-types.sync="filterTypes"
  7. :filter-btn-name="$t('common.screen')"
  8. @select-value="handleFilterUser"
  9. />
  10. </div>
  11. <el-table :data="tableData" stripe style="width: 100%;" :height="tool.getTableHeight()" @selection-change="handleSelectionChange">
  12. <el-table-column type="selection" width="55" />
  13. <el-table-column prop="ROLE_NAME" :label="$t('Administrator.role')">
  14. <template slot-scope="scope">
  15. <el-tag type="warning" size="small" class="no-border">{{ scope.row.ROLE_NAME }}</el-tag>
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="REMARK" :label="$t('Administrator.remark')" />
  19. <el-table-column :label="$t('Administrator.creatUser')">
  20. <template slot-scope="scope">
  21. {{ scope.row.CREATE_ADMIN_NAME }}
  22. </template>
  23. </el-table-column>
  24. <el-table-column :label="$t('Administrator.creatAt')">
  25. <template slot-scope="scope">
  26. {{ tool.formatDate(scope.row.CREATED_AT) }}
  27. </template>
  28. </el-table-column>
  29. <el-table-column :label="$t('Administrator.updateUser')">
  30. <template slot-scope="scope">
  31. {{ scope.row.UPDATE_ADMIN_NAME }}
  32. </template>
  33. </el-table-column>
  34. <el-table-column :label="$t('Administrator.updateAt')">
  35. <template slot-scope="scope">
  36. {{ tool.formatDate(scope.row.UPDATED_AT) }}
  37. </template>
  38. </el-table-column>
  39. <el-table-column :fixed="fixedColumn" :label="$t('table.actions')" width="180">
  40. <template slot-scope="scope">
  41. <el-dropdown v-if="scope.row.DONT_DEL==='0'&&(permission.hasPermission(`admin/role-permission`)||permission.hasPermission(`admin/role-edit`)||permission.hasPermission(`admin/role-delete`))" size="small" trigger="click" @command="handleRow" @click.stop="">
  42. <el-button type="primary" size="small">
  43. {{ $t('common.actionThisData') }}<i class="el-icon-arrow-down el-icon--right" />
  44. </el-button>
  45. <el-dropdown-menu slot="dropdown">
  46. <el-dropdown-item v-if="permission.hasPermission(`admin/role-permission`)" :command="`permission|${scope.row.ID}`">{{ $t('permission.permission') }}</el-dropdown-item>
  47. <!-- <el-dropdown-item :command="`column|${scope.row.ID}`" v-if="permission.hasPermission(`admin/role-column`)">列表字段权限</el-dropdown-item>-->
  48. <el-dropdown-item v-if="permission.hasPermission(`admin/role-edit`)" :command="`edit|${scope.row.ID}`">{{ $t('table.edit') }}</el-dropdown-item>
  49. <el-dropdown-item v-if="permission.hasPermission(`admin/role-delete`)" :command="`delete|${scope.row.ID}`">{{ $t('table.delete') }}</el-dropdown-item>
  50. </el-dropdown-menu>
  51. </el-dropdown>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <div class="white-box-footer">
  56. <el-dropdown v-if="permission.hasPermission(`admin/role-delete`)" size="small" trigger="click" @command="muliDelHandle">
  57. <el-button type="primary" size="small">
  58. {{ $t('Administrator.selectData') }}<i class="el-icon-arrow-down el-icon--right" />
  59. </el-button>
  60. <el-dropdown-menu slot="dropdown">
  61. <el-dropdown-item command="delete">{{ $t('table.delete') }}</el-dropdown-item>
  62. </el-dropdown-menu>
  63. </el-dropdown>
  64. <el-button v-if="permission.hasPermission(`admin/role-add`)" type="primary" size="small" icon="el-icon-plus" @click="onAdd">{{ $t('Administrator.addRole') }}</el-button>
  65. <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  66. </div>
  67. </div>
  68. </div>
  69. </template>
  70. <script>
  71. import { deleteRole, adminRole, batchDeleteRole } from '@/api/filter'
  72. import tool from '@/utils/tool'
  73. import FilterUser from '@/components/FilterUser'
  74. import permission from '@/utils/permission'
  75. import Pagination from '@/components/Pagination'
  76. import filterHelper from '@/utils/filterHelper'
  77. import {getOperatingSystem, getScreenWidth} from "@/utils"
  78. export default {
  79. name: 'Role',
  80. components: { FilterUser, Pagination },
  81. data() {
  82. return {
  83. fixedColumn:false, // 固定,当手机端不固定,pc固定
  84. tableData: null,
  85. loading: true,
  86. multipleSelection: [],
  87. currentPage: 1,
  88. totalPages: 1,
  89. totalCount: 1,
  90. pageSize: 20,
  91. tool: tool,
  92. permission: permission,
  93. filterData: null,
  94. filterTypes: {
  95. 'ROLE_NAME': { isUserTable: false, name: this.$t('Administrator.role') },
  96. 'REMARK': { isUserTable: false, name: this.$t('Administrator.remark') },
  97. 'CREATE_ADMIN_NAME': { isUserTable: false, name: this.$t('Administrator.creatUser') },
  98. 'CREATED_AT': { isUserTable: false, name: this.$t('Administrator.creatAt'), other: 'date' },
  99. 'UPDATE_ADMIN_NAME': { isUserTable: false, name: this.$t('Administrator.updateUser') },
  100. 'UPDATED_AT': { isUserTable: false, name: this.$t('Administrator.updateAt'), other: 'date' }
  101. },
  102. filterModel: {}
  103. }
  104. },
  105. created() {
  106. },
  107. mounted() {
  108. this.getData()
  109. // let system = getOperatingSystem()
  110. // if (system == "Android" || system == 'ios') {
  111. // this.fixedColumn = false
  112. // } else {
  113. // this.fixedColumn = 'right'
  114. // }
  115. this.fixedColumn = getScreenWidth() < 500 ? false : 'right'
  116. },
  117. methods: {
  118. handleSelectionChange(val) {
  119. this.multipleSelection = val
  120. },
  121. handleCurrentChange(page) {
  122. this.getData(page, this.pageSize)
  123. },
  124. handleSizeChange(pageSize) {
  125. this.getData(this.currentPage, pageSize)
  126. },
  127. handleRow(command) {
  128. const re = command.split('|')
  129. this.handleCommand(re[0], re[1])
  130. },
  131. handleCommand(command, id) {
  132. if (command === 'edit') {
  133. this.$router.push({ path: `/admin/role-edit/${id}` })
  134. } else if (command === 'permission') {
  135. this.$router.push({ path: `/admin/role-permission/${id}` })
  136. } else if (command === 'column') {
  137. this.$router.push({ path: `/admin/role-column/${id}` })
  138. } else if (command === 'delete') {
  139. this.delHandle(this, id)
  140. }
  141. },
  142. onAdd() {
  143. this.$router.push({ path: `/admin/role-add` })
  144. },
  145. delHandle(obj, id) {
  146. obj.$confirm(this.$t('common.deleteTips'), this.$t('common.hint'), {
  147. confirmButtonText: this.$t('common.confirm'),
  148. cancelButtonText: this.$t('common.cancel'),
  149. type: 'warning'
  150. }).then(() => {
  151. deleteRole(id).then(response => {
  152. this.$message({
  153. message: response.data,
  154. type: 'success'
  155. })
  156. this.getData()
  157. }).catch(err => {
  158. console.log('err---------' + err)
  159. })
  160. })
  161. },
  162. muliDelHandle(command) {
  163. if (command === 'delete') {
  164. this.$confirm(this.$t('common.deleteTips'), this.$t('common.hint'), {
  165. confirmButtonText: this.$t('common.confirm'),
  166. cancelButtonText: this.$t('common.cancel'),
  167. type: 'warning'
  168. }).then(() => {
  169. const selectedIds = []
  170. for (const val of this.multipleSelection) {
  171. selectedIds.push(val.ID)
  172. }
  173. batchDeleteRole({
  174. selected: selectedIds
  175. }).then(response => {
  176. this.$message({
  177. message: response.data,
  178. type: 'success'
  179. })
  180. this.getData()
  181. }).catch(err => {
  182. console.log('err---------' + err)
  183. })
  184. })
  185. }
  186. },
  187. handleFilterUser(filterData) {
  188. filterHelper.handleFilterUser(this, filterData)
  189. },
  190. handleFilter() {
  191. this.getData()
  192. },
  193. getData(page, pageSize) {
  194. const filterData = this.filterModel
  195. const vueObj = this
  196. const paramsData = Object.assign({
  197. page: (page === null || page == undefined) ? 1 : page,
  198. pageSize: (pageSize === null || pageSize == undefined) ? vueObj.pageSize : pageSize
  199. }, filterData)
  200. adminRole(paramsData).then(response => {
  201. vueObj.tableData = response.data.list
  202. vueObj.currentPage = page
  203. vueObj.totalPages = parseInt(response.data.totalPages)
  204. vueObj.totalCount = parseInt(response.data.totalCount)
  205. vueObj.pageSize = pageSize
  206. this.loading = false
  207. }).catch(err => {
  208. console.log('err=============' + err)
  209. this.loading = false
  210. })
  211. }
  212. }
  213. }
  214. </script>
  215. <style>
  216. .el-table th > .cell {
  217. padding-left: 14px !important;
  218. padding-right: 14px !important;
  219. }
  220. .el-table__fixed-right-patch {
  221. width: 0px !important;
  222. }
  223. .pagination-container {
  224. float: right;
  225. padding: 0px 0px !important;
  226. margin: 0 0;
  227. }
  228. .white-box-footer .el-dropdown {
  229. margin-right: 10px;
  230. }
  231. </style>