role.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template lang="html">
  2. <div id="role">
  3. <el-row class="register">
  4. <el-col :span="24" class="btn">
  5. <el-row :gutter="10">
  6. <el-col :span="20"><h3>角色管理</h3></el-col>
  7. <!-- 批量导入按钮没加 -->
  8. <el-col :span="4"><el-button type="success" icon="el-icon-plus" @click="openDialog()">角色添加</el-button></el-col>
  9. </el-row>
  10. </el-col>
  11. <el-col :span="24" class="search">
  12. <el-col :span="5" class="searchInp"><el-input v-model="input" placeholder="请输入内容"></el-input></el-col>
  13. <el-col :span="2" class="searchBtn"><el-button icon="el-icon-search"></el-button></el-col>
  14. </el-col>
  15. <el-col :span="24" class="list">
  16. <el-table :data="tableData" style="width: 100%" border stripe>
  17. <el-table-column prop="name" align="center" label="角色名称"> </el-table-column>
  18. <el-table-column label="操作" align="center">
  19. <template v-slot="scoped">
  20. <el-row type="flex" justify="center">
  21. <el-col :span="6">
  22. <el-button size="mini" type="text" @click="openDialog(scoped.$index, 'update')">修改</el-button>
  23. </el-col>
  24. <el-col :span="6">
  25. <el-button size="mini" type="text" @click="openDialog(scoped.$index, 'assign')">分配人员</el-button>
  26. </el-col>
  27. </el-row>
  28. </template>
  29. </el-table-column>
  30. </el-table>
  31. <el-col class="paging">
  32. <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination>
  33. </el-col>
  34. </el-col>
  35. </el-row>
  36. <el-dialog title="角色编辑" :visible.sync="dialog">
  37. <el-form :model="form" label-position="left" label-width="auto" style="padding: 0 5px;">
  38. <el-row>
  39. <el-col :span="24">
  40. <el-form-item label="角色名称">
  41. <el-input v-model="form.name" clearable></el-input>
  42. </el-form-item>
  43. </el-col>
  44. </el-row>
  45. </el-form>
  46. <div slot="footer" class="dialog-footer">
  47. <el-button @click="handleCancel">取 消</el-button>
  48. <el-button type="primary" @click="handleEdit">确 定</el-button>
  49. </div>
  50. </el-dialog>
  51. <el-dialog title="分配人员" :visible.sync="dialogAssign" style="padding:0 5rem;">
  52. <el-transfer v-model="assignFrom.personList" :data="personList" :titles="['未添加', '已添加']" :button-texts="['删除', '添加']"></el-transfer>
  53. <div slot="footer" class="dialog-footer">
  54. <el-button @click="dialogAssign = false">取 消</el-button>
  55. <el-button type="primary" @click="handleAssign">确 定</el-button>
  56. </div>
  57. </el-dialog>
  58. </div>
  59. </template>
  60. <script>
  61. export default {
  62. name: 'role',
  63. props: {},
  64. components: {},
  65. data: () => ({
  66. input: '',
  67. textarea: '',
  68. tableData: [
  69. {
  70. name: '角色1',
  71. personList: [1],
  72. },
  73. {
  74. name: '角色2',
  75. personList: [2, 3],
  76. },
  77. {
  78. name: '角色3',
  79. },
  80. {
  81. name: '角色4',
  82. },
  83. ],
  84. personList: [],
  85. value: '',
  86. dialog: false,
  87. dialogAssign: false,
  88. form: {},
  89. assignFrom: {},
  90. }),
  91. created() {
  92. let list = [];
  93. for (let i = 0; i < 10; i++) {
  94. list.push({
  95. key: i,
  96. label: `人员${i}`,
  97. });
  98. }
  99. this.$set(this, `personList`, list);
  100. },
  101. computed: {},
  102. methods: {
  103. handleEdit() {
  104. let chData = this.form;
  105. const { index, ...form } = chData;
  106. form['state'] = 1;
  107. console.log(index, form);
  108. if (index !== undefined) {
  109. this.$set(this.tableData, `${index}`, form);
  110. this.$message.success('修改成功');
  111. } else {
  112. this.tableData.push(form);
  113. }
  114. this.handleCancel();
  115. },
  116. handleCancel() {
  117. this.form = {};
  118. this.dialog = false;
  119. },
  120. openDialog(index, type) {
  121. if (index !== undefined) {
  122. let data = JSON.parse(JSON.stringify(this.tableData[index]));
  123. data[`index`] = index;
  124. if (type === 'update') {
  125. this.dialog = true;
  126. this.$set(this, `form`, data);
  127. } else {
  128. this.dialogAssign = true;
  129. this.$set(this, `assignFrom`, data);
  130. }
  131. } else {
  132. this.form = {};
  133. this.dialog = true;
  134. }
  135. },
  136. handleAssign() {
  137. let data = this.assignFrom;
  138. const { index, ...form } = data;
  139. this.$set(this.tableData[index], `personList`, form.personList);
  140. this.dialogAssign = false;
  141. },
  142. handleClose(done) {
  143. this.$confirm('确认关闭?')
  144. .then(_ => {
  145. done();
  146. })
  147. .catch(_ => {});
  148. },
  149. },
  150. };
  151. </script>
  152. <style lang="scss" scoped>
  153. h1,
  154. h2,
  155. h3,
  156. h4,
  157. h5,
  158. h6 {
  159. margin: 0;
  160. padding: 0;
  161. }
  162. .register {
  163. width: 100%;
  164. padding: 20px;
  165. }
  166. .btn {
  167. width: 100%;
  168. height: 40px;
  169. line-height: 40px;
  170. margin: 20px 0;
  171. }
  172. .search {
  173. height: 40px;
  174. line-height: 40px;
  175. margin: 0 0 20px 0;
  176. }
  177. .searchSel .el-select {
  178. border-radius: 0;
  179. }
  180. /deep/.searchInp .el-input__inner {
  181. border-radius: 0;
  182. }
  183. .searchBtn .el-button {
  184. border-radius: 0;
  185. }
  186. .paging {
  187. text-align: right;
  188. margin: 10px 0;
  189. }
  190. .sizeA {
  191. padding: 30px;
  192. }
  193. </style>