RoleList.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <a-card :bordered="false">
  3. <div class="table-page-search-wrapper">
  4. <a-form layout="inline">
  5. <a-row :gutter="48">
  6. <a-col :md="8" :sm="24">
  7. <a-form-item label="角色ID">
  8. <a-input placeholder="请输入"/>
  9. </a-form-item>
  10. </a-col>
  11. <a-col :md="8" :sm="24">
  12. <a-form-item label="状态">
  13. <a-select placeholder="请选择" default-value="0">
  14. <a-select-option value="0">全部</a-select-option>
  15. <a-select-option value="1">关闭</a-select-option>
  16. <a-select-option value="2">运行中</a-select-option>
  17. </a-select>
  18. </a-form-item>
  19. </a-col>
  20. <a-col :md="8" :sm="24">
  21. <span class="table-page-search-submitButtons">
  22. <a-button type="primary">查询</a-button>
  23. <a-button style="margin-left: 8px">重置</a-button>
  24. </span>
  25. </a-col>
  26. </a-row>
  27. </a-form>
  28. </div>
  29. <s-table
  30. size="default"
  31. :columns="columns"
  32. :data="loadData"
  33. >
  34. <div
  35. slot="expandedRowRender"
  36. slot-scope="record"
  37. style="margin: 0">
  38. <a-row
  39. :gutter="24"
  40. :style="{ marginBottom: '12px' }">
  41. <a-col :span="12" v-for="(role, index) in record.permissions" :key="index" :style="{ marginBottom: '12px' }">
  42. <a-col :span="4">
  43. <span>{{ role.permissionName }}:</span>
  44. </a-col>
  45. <a-col :span="20" v-if="role.actionEntitySet.length > 0">
  46. <a-tag color="cyan" v-for="(action, k) in role.actionEntitySet" :key="k">{{ action.describe }}</a-tag>
  47. </a-col>
  48. <a-col :span="20" v-else>-</a-col>
  49. </a-col>
  50. </a-row>
  51. </div>
  52. <span slot="action" slot-scope="text, record">
  53. <a @click="handleEdit(record)">编辑</a>
  54. <a-divider type="vertical" />
  55. <a-dropdown>
  56. <a class="ant-dropdown-link">
  57. 更多 <a-icon type="down" />
  58. </a>
  59. <a-menu slot="overlay">
  60. <a-menu-item>
  61. <a href="javascript:;">详情</a>
  62. </a-menu-item>
  63. <a-menu-item>
  64. <a href="javascript:;">禁用</a>
  65. </a-menu-item>
  66. <a-menu-item>
  67. <a href="javascript:;">删除</a>
  68. </a-menu-item>
  69. </a-menu>
  70. </a-dropdown>
  71. </span>
  72. </s-table>
  73. <a-modal
  74. title="操作"
  75. style="top: 20px;"
  76. :width="800"
  77. v-model="visible"
  78. @ok="handleOk"
  79. >
  80. <a-form :autoFormCreate="(form)=>{this.form = form}">
  81. <a-form-item
  82. :labelCol="labelCol"
  83. :wrapperCol="wrapperCol"
  84. label='唯一识别码'
  85. hasFeedback
  86. validateStatus='success'
  87. >
  88. <a-input placeholder='唯一识别码' v-model="mdl.id" id='no' disabled="disabled" />
  89. </a-form-item>
  90. <a-form-item
  91. :labelCol="labelCol"
  92. :wrapperCol="wrapperCol"
  93. label='角色名称'
  94. hasFeedback
  95. validateStatus='success'
  96. >
  97. <a-input placeholder='起一个名字' v-model="mdl.name" id='role_name' />
  98. </a-form-item>
  99. <a-form-item
  100. :labelCol="labelCol"
  101. :wrapperCol="wrapperCol"
  102. label='状态'
  103. hasFeedback
  104. validateStatus='warning'
  105. >
  106. <a-select v-model="mdl.status">
  107. <a-select-option value='1'>正常</a-select-option>
  108. <a-select-option value='2'>禁用</a-select-option>
  109. </a-select>
  110. </a-form-item>
  111. <a-form-item
  112. :labelCol="labelCol"
  113. :wrapperCol="wrapperCol"
  114. label='描述'
  115. hasFeedback
  116. >
  117. <a-textarea :rows="5" v-model="mdl.describe" placeholder="..." id='describe'/>
  118. </a-form-item>
  119. <a-divider />
  120. <a-form-item
  121. :labelCol="labelCol"
  122. :wrapperCol="wrapperCol"
  123. label='拥有权限'
  124. hasFeedback
  125. >
  126. <a-row :gutter="16" v-for="(permission, index) in mdl.permissions" :key="index">
  127. <a-col :span="4">
  128. {{ permission.permissionName }}:
  129. </a-col>
  130. <a-col :span="20">
  131. <a-checkbox-group :options="permission.actionsOptions"/>
  132. </a-col>
  133. </a-row>
  134. </a-form-item>
  135. </a-form>
  136. </a-modal>
  137. </a-card>
  138. </template>
  139. <script>
  140. import STable from '@/components/table/'
  141. export default {
  142. name: "TableList",
  143. components: {
  144. STable
  145. },
  146. data () {
  147. return {
  148. description: '列表使用场景:后台管理中的权限管理以及角色管理,可用于基于 RBAC 设计的角色权限控制,颗粒度细到每一个操作类型。',
  149. visible: false,
  150. labelCol: {
  151. xs: { span: 24 },
  152. sm: { span: 5 },
  153. },
  154. wrapperCol: {
  155. xs: { span: 24 },
  156. sm: { span: 16 },
  157. },
  158. form: null,
  159. mdl: {},
  160. // 高级搜索 展开/关闭
  161. advanced: false,
  162. // 查询参数
  163. queryParam: {},
  164. // 表头
  165. columns: [
  166. {
  167. title: '唯一识别码',
  168. dataIndex: 'id'
  169. },
  170. {
  171. title: '角色名称',
  172. dataIndex: 'name',
  173. },
  174. {
  175. title: '状态',
  176. dataIndex: 'status'
  177. },
  178. {
  179. title: '创建时间',
  180. dataIndex: 'createTime',
  181. sorter: true
  182. }, {
  183. title: '操作',
  184. width: '150px',
  185. dataIndex: 'action',
  186. scopedSlots: { customRender: 'action' },
  187. }
  188. ],
  189. // 加载数据方法 必须为 Promise 对象
  190. loadData: parameter => {
  191. return this.$http.get('/role', {
  192. params: Object.assign(parameter, this.queryParam)
  193. }).then(res => {
  194. return res.result
  195. })
  196. },
  197. selectedRowKeys: [],
  198. selectedRows: []
  199. }
  200. },
  201. methods: {
  202. handleEdit (record) {
  203. this.mdl = Object.assign({}, record)
  204. this.mdl.permissions.forEach(permission => {
  205. permission.actionsOptions = permission.actionEntitySet.map(action => {
  206. return { label: action.describe, value: action.action, defaultCheck: action.defaultCheck }
  207. })
  208. })
  209. console.log(this.mdl)
  210. this.visible = true
  211. },
  212. handleOk () {
  213. },
  214. onChange (selectedRowKeys, selectedRows) {
  215. this.selectedRowKeys = selectedRowKeys
  216. this.selectedRows = selectedRows
  217. },
  218. toggleAdvanced () {
  219. this.advanced = !this.advanced
  220. },
  221. },
  222. watch: {
  223. /*
  224. 'selectedRows': function (selectedRows) {
  225. this.needTotalList = this.needTotalList.map(item => {
  226. return {
  227. ...item,
  228. total: selectedRows.reduce( (sum, val) => {
  229. return sum + val[item.dataIndex]
  230. }, 0)
  231. }
  232. })
  233. }
  234. */
  235. }
  236. }
  237. </script>