index.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <div class="main-content__div">
  3. <div class="table-box__div" v-cloak v-loading="loadingFlag">
  4. <el-form class="demo-form-inline">
  5. <el-form-item label="角色名称">
  6. <el-input
  7. placeholder="角色名称"
  8. v-model="keyword"
  9. style="width:150px;"
  10. size="small"
  11. >
  12. </el-input>
  13. </el-form-item>
  14. <!-- 搜索按钮 -->
  15. <el-form-item>
  16. <el-button type="primary" size="small" @click="searchFrom()">搜索</el-button>
  17. </el-form-item>
  18. </el-form>
  19. </div>
  20. <!-- 列表 -->
  21. <div class="table-box__div" v-cloak v-loading="loadingFlag">
  22. <!-- 查询表单 -->
  23. <el-form :inline="true" class="demo-form-inline">
  24. <el-form-item>
  25. <el-button type="primary" size="small" @click="addClick">添加角色</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <el-table
  29. size="mini"
  30. :data="tableData"
  31. :empty-text="tableDataLoadingText"
  32. style="width: 100%;font-size: 15px;"
  33. :header-cell-style="{background:'#FAFAFA'}"
  34. >
  35. <el-table-column label="编号" width="250" prop="id"></el-table-column>
  36. <el-table-column label="角色名称" prop="role_name" width="350"></el-table-column>
  37. <el-table-column label="角色备注" prop="remark" width="300"></el-table-column>
  38. <el-table-column label="操作时间" prop="updated_at" width="300"></el-table-column>
  39. <el-table-column label="排序" prop="sort" width="50"></el-table-column>
  40. <el-table-column prop="" label="操作" align="center" fixed="right" width="200">
  41. <template v-slot="scope">
  42. <div style="display: flex;flex-direction: row;justify-content: center;align-items: center;" v-if="scope.row.rule[0]!='0'">
  43. <span class="btn" @click="assignPermissions(scope.row, scope.$index)">分配权限</span>
  44. <span class="btn" @click="updateClick(scope.row, scope.$index)">编辑</span>
  45. <span class="btn" @click="deleteAuthority(scope.row,scope.$index)">删除</span>
  46. </div>
  47. </template>
  48. </el-table-column>
  49. </el-table>
  50. <!-- 分页 -->
  51. <div class="block" v-show="pagination" style="margin-top: 10px;float: right;">
  52. <el-pagination
  53. background
  54. @current-change="handleCurrentChange"
  55. :current-page="currentPage"
  56. :page-size="pageSize"
  57. layout="total, prev, pager, next, jumper"
  58. :total="parseInt(tableCount)">
  59. </el-pagination>
  60. </div>
  61. </div>
  62. </div>
  63. <Dialog title="温馨提示" content="您确认要删除该角色吗?"
  64. @close="DialogShow = false"
  65. @submitSureClick="submitSureClickDel"
  66. @DialogFalse="DialogShow = false"
  67. :innerVisible="DialogShow">
  68. </Dialog>
  69. <DialogSlot
  70. title="添加/编辑"
  71. @close="roleDialogShow = false"
  72. @DialogClose="roleDialogShow = false"
  73. :innerVisible="roleDialogShow"
  74. @colesClick="roleDialogShow = false"
  75. >
  76. <editFrom
  77. @colesClick="roleDialogShow = false"
  78. :roleDataForm="roleDataForm"
  79. :isloading="isloading"
  80. @roleSubmitClick="roleSubmitClick"
  81. @closeDlg="closeDlg"
  82. >
  83. </editFrom>
  84. </DialogSlot>
  85. <DialogSlot
  86. title="添加权限/编辑权限"
  87. @close="authorityDialogShow = false"
  88. @DialogClose="authorityDialogShow = false"
  89. :innerVisible="authorityDialogShow"
  90. @colesClick="authorityDialogShow = false"
  91. >
  92. <authorityFrom
  93. @colesClick="authorityDialogShow = false"
  94. :authorityDataForm="authorityDataForm"
  95. :isloading="isloading"
  96. @authoritySubmitClick="authoritySubmitClick"
  97. @closeDlg="closeDlg"
  98. >
  99. </authorityFrom>
  100. </DialogSlot>
  101. </template>
  102. <script>
  103. import Dialog from "../../components/dialog";
  104. import editFrom from "./components/edit";
  105. import authorityFrom from "./components/authority";
  106. import DialogSlot from "../../components/DialogSlot";
  107. import router from "../../router";
  108. export default {
  109. components: {
  110. Dialog,
  111. editFrom,
  112. DialogSlot,
  113. authorityFrom
  114. },
  115. data() {
  116. return {
  117. value:"1",
  118. // 菜单列表数据
  119. tableData: [],
  120. // 加载中数据提示
  121. tableDataLoadingText:"拼命加载中······",
  122. // 是否显示分页
  123. pagination:false,
  124. // 每页显示的条数
  125. pageSize:10,
  126. // 当前页
  127. currentPage:1,
  128. // 菜单列表数据总条数
  129. tableCount:0,
  130. loadingFlag: false,
  131. isShowSource: false, // 是否显示来源列
  132. id:0,
  133. DialogShow: false, //控制删除弹窗
  134. roleId:'',
  135. roleRowIndex:'',
  136. roleDataForm: {},
  137. roleTableData: [],
  138. isloading:false, //提交按钮状态
  139. roleDialogShow: false, // 控制保存弹窗
  140. authorityDialogShow:false,
  141. authorityDataForm: {},
  142. keyword:'',
  143. }
  144. },
  145. mounted() {},
  146. methods: {
  147. // 获取菜单信息列表
  148. getList:function(){
  149. let _t = this;
  150. _t.loadingFlag = true;
  151. let parames = {
  152. 'page':this.currentPage,
  153. 'pageSize':this.pageSize,
  154. 'keyword':this.keyword
  155. }
  156. console.log("**************")
  157. this.$api.user.roleList(parames).then(res=>{
  158. _t.loadingFlag = false;
  159. if(res.code==200){
  160. if(res.data.rows.length==0){
  161. this.$message.error("没找到该角色!!!")
  162. return
  163. }
  164. _t.tableData = res.data.rows;
  165. _t.tableCount = res.data.count;
  166. // 总条数大于每页显示的条数时显示分页
  167. if( _t.tableCount > _t.pageSize ){
  168. _t.pagination = true;
  169. }
  170. if( _t.tableData.length==0 ){
  171. _t.tableDataLoadingText = "暂无数据";
  172. }
  173. }else{
  174. this.$message.error("查询失败")
  175. }
  176. })
  177. },
  178. // 点击翻页
  179. handleCurrentChange(val) {
  180. this.currentPage = val;
  181. this.getList();
  182. },
  183. // 查看下一级
  184. nextClick( id ){
  185. let _t = this;
  186. _t.id = id
  187. _t.currentPage = 1
  188. _t.pageSize = 10
  189. this.getList()
  190. },
  191. addClick(){
  192. this.roleDataForm = {}
  193. this.roleDialogShow = true
  194. },
  195. //更新角色
  196. updateClick(row,index){
  197. console.log(row)
  198. this.roleDataForm = row
  199. this.rowIndex = index
  200. this.roleDialogShow = true
  201. },
  202. closeDlg(val){
  203. console.log("aaaaaa",val)
  204. this.roleDialogShow = false
  205. this.isloading = false
  206. this.authorityDialogShow = false
  207. },
  208. roleSubmitClick(data){
  209. let _t = this
  210. console.log("提交数据",data)
  211. let parames = data
  212. _t.isloading = true
  213. //有id更新,没有新增
  214. if(parames.id){
  215. this.$api.user.updateRole(parames).then(res=>{
  216. _t.loadingFlag = false;
  217. if(res.code==200){
  218. _t.tableData[_t.rowIndex] = parames
  219. console.log("修改成功")
  220. this.getList()
  221. }else{
  222. this.$message.error("修改失败")
  223. }
  224. this.roleDialogShow = false
  225. this.isloading = false
  226. })
  227. }else{
  228. this.$api.user.addRole(parames).then(res=>{
  229. _t.loadingFlag = false;
  230. if(res.code==200){
  231. console.log("创建成功")
  232. this.getList()
  233. }else{
  234. this.$message.error(res.message)
  235. }
  236. this.roleDialogShow = false
  237. this.isloading = false
  238. })
  239. }
  240. },
  241. //
  242. authoritySubmitClick(data){
  243. let _t = this
  244. console.log("提交数据",data)
  245. let parames = {
  246. rule:data,
  247. id: this.authorityDataForm.id,
  248. role_name:this.authorityDataForm.role_name,
  249. }
  250. _t.isloading = true
  251. //有id更新,没有新增
  252. this.$api.user.updateRole(parames).then(res=>{
  253. _t.loadingFlag = false;
  254. if(res.code==200){
  255. _t.tableData[_t.rowIndex] = parames
  256. this.$message.success("分配成功")
  257. _t.authorityDialogShow = false
  258. this.getList()
  259. }else{
  260. this.$message.error("分配失败")
  261. }
  262. this.authorityDialogShow = false
  263. this.isloading = false
  264. })
  265. },
  266. //删除菜单
  267. deleteAuthority(row, index) {
  268. this.roleId = row.id
  269. this.roleRowIndex = index
  270. this.DialogShow = true
  271. },
  272. submitSureClickDel(row,index){
  273. let parames = {
  274. 'id':this.roleId
  275. }
  276. this.$api.user.delRole(parames).then(res=>{
  277. if(res.code==200){
  278. this.DialogShow = false
  279. this.getList()
  280. }else{
  281. this.$message.error("删除失败")
  282. }
  283. })
  284. },
  285. searchFrom(){
  286. this.currentPage = 1
  287. this.pageSize = 10
  288. this.getList()
  289. },
  290. assignPermissions(row,index){
  291. console.log(row)
  292. this.authorityDataForm = row
  293. this.rowIndex = index
  294. this.authorityDialogShow = true
  295. }
  296. },
  297. created() {
  298. this.getList();
  299. }
  300. }
  301. </script>
  302. <style >
  303. .demo-form-inline{
  304. display: flex;
  305. }
  306. .demo-form-inline .el-form-item{
  307. margin: 0 20px;
  308. }
  309. </style>