index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="main-content__div">
  3. <!-- 列表 -->
  4. <div class="table-box__div" v-cloak v-loading="loadingFlag">
  5. <!-- 查询表单 -->
  6. <el-form :inline="true" class="demo-form-inline">
  7. <el-form-item>
  8. <el-button type="primary" size="small" @click="addClick">添加菜单</el-button>
  9. </el-form-item>
  10. </el-form>
  11. <el-table
  12. size="mini"
  13. :data="tableData"
  14. :empty-text="tableDataLoadingText"
  15. style="width: 100%;font-size: 15px;"
  16. :header-cell-style="{background:'#FAFAFA'}"
  17. >
  18. <el-table-column label="编号" width="150" prop="id"></el-table-column>
  19. <el-table-column label="菜单名称" prop="label" width="250"></el-table-column>
  20. <el-table-column label="路由地址" prop="url" width="200"></el-table-column>
  21. <el-table-column label="图标" prop="icon" width="200"></el-table-column>
  22. <el-table-column label="排序" prop="sort" width="200"></el-table-column>
  23. <el-table-column label="是否外链" width="200" prop="is_links">
  24. <template v-slot="{row}">
  25. <el-switch
  26. v-model="row.is_links"
  27. :active-value="1"
  28. :inactive-value="0"
  29. disabled
  30. ></el-switch>
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="是否隐藏" width="200">
  34. <template v-slot="{row}">
  35. <el-switch
  36. v-model="row.hidden"
  37. :active-value="1"
  38. :inactive-value="0"
  39. disabled
  40. ></el-switch>
  41. </template>
  42. </el-table-column>
  43. <el-table-column prop="" label="操作" align="center" >
  44. <template v-slot="scope">
  45. <div style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
  46. <span class="btn " @click="nextClick(scope.row.id)">查看下级</span>
  47. <span class="btn" @click="updateClick(scope.row, scope.$index)">编辑</span>
  48. <span class="btn" @click="deleteAuthority(scope.row,scope.$index)">删除</span>
  49. </div>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. <!-- 分页 -->
  54. <div class="block" v-show="pagination" style="margin-top: 10px;float: right;">
  55. <el-pagination
  56. background
  57. @current-change="handleCurrentChange"
  58. :current-page="currentPage"
  59. :page-size="pageSize"
  60. layout="total, prev, pager, next, jumper"
  61. :total="parseInt(tableCount)">
  62. </el-pagination>
  63. </div>
  64. </div>
  65. </div>
  66. <Dialog title="温馨提示" content="您确认要删除该菜单吗?"
  67. @close="DialogShow = false"
  68. @submitSureClick="submitSureClickDel"
  69. @DialogFalse="DialogShow = false"
  70. :innerVisible="DialogShow">
  71. </Dialog>
  72. <DialogSlot
  73. title="添加/编辑"
  74. @close="menuDialogShow = false"
  75. @DialogClose="menuDialogShow = false"
  76. :innerVisible="menuDialogShow"
  77. @colesClick="menuDialogShow = false"
  78. >
  79. <editFrom
  80. @colesClick="menuDialogShow = false"
  81. :menuDataForm="menuDataForm"
  82. :isloading="isloading"
  83. @menuSubmitClick="menuSubmitClick"
  84. @closeDlg="closeDlg"
  85. >
  86. </editFrom>
  87. </DialogSlot>
  88. </template>
  89. <script>
  90. import Dialog from "../../components/dialog";
  91. import editFrom from "./components/edit";
  92. import DialogSlot from "../../components/DialogSlot";
  93. export default {
  94. components: {
  95. Dialog,
  96. editFrom,
  97. DialogSlot
  98. },
  99. data() {
  100. return {
  101. value:"1",
  102. // 菜单列表数据
  103. tableData: [],
  104. // 加载中数据提示
  105. tableDataLoadingText:"拼命加载中······",
  106. // 是否显示分页
  107. pagination:false,
  108. // 每页显示的条数
  109. pageSize:10,
  110. // 当前页
  111. currentPage:1,
  112. // 菜单列表数据总条数
  113. tableCount:0,
  114. loadingFlag: false,
  115. isShowSource: false, // 是否显示来源列
  116. id:0,
  117. DialogShow: false, //控制删除弹窗
  118. MenuId:'',
  119. MenuRowIndex:'',
  120. menuDataForm: {},
  121. menuTableData: [],
  122. isloading:false, //提交按钮状态
  123. menuDialogShow: false, // 控制保存弹窗
  124. }
  125. },
  126. mounted() {},
  127. methods: {
  128. // 获取菜单信息列表
  129. getList:function(){
  130. let _t = this;
  131. _t.loadingFlag = true;
  132. let parames = {
  133. 'page':this.currentPage,
  134. 'pageSize':this.pageSize,
  135. 'id':this.id
  136. }
  137. this.$api.authority.getMenuList(parames).then(res=>{
  138. _t.loadingFlag = false;
  139. if(res.code==200){
  140. if(res.data.rows.length==0){
  141. this.$message.error("没有下级了,休息一下吧!!!")
  142. return
  143. }
  144. _t.tableData = res.data.rows;
  145. _t.tableCount = res.data.count;
  146. // 总条数大于每页显示的条数时显示分页
  147. if( _t.tableCount > _t.pageSize ){
  148. _t.pagination = true;
  149. }
  150. if( _t.tableData.length==0 ){
  151. _t.tableDataLoadingText = "暂无数据";
  152. }
  153. }else{
  154. this.$message.error("查询失败")
  155. }
  156. })
  157. },
  158. // 点击翻页
  159. handleCurrentChange(val) {
  160. this.currentPage = val;
  161. this.getList();
  162. },
  163. // 查看下一级
  164. nextClick( id ){
  165. let _t = this;
  166. _t.id = id
  167. _t.currentPage = 1
  168. _t.pageSize = 10
  169. this.getList()
  170. },
  171. addClick(){
  172. this.menuDataForm = {}
  173. this.menuDialogShow = true
  174. },
  175. //更新菜单
  176. updateClick(row,index){
  177. console.log(row)
  178. this.menuDataForm = row
  179. this.rowIndex = index
  180. this.menuDialogShow = true
  181. },
  182. // menuDialogShow(){
  183. // this.isloading = false
  184. // },
  185. closeDlg(val){
  186. console.log("aaaaaa",val)
  187. this.menuDialogShow = false
  188. this.isloading = false
  189. },
  190. menuSubmitClick(data){
  191. let _t = this
  192. console.log("提交数据",data)
  193. let parames = data
  194. _t.isloading = true
  195. //有id更新,没有新增
  196. if(parames.id){
  197. this.$api.authority.updateMenu(parames).then(res=>{
  198. _t.loadingFlag = false;
  199. if(res.code==200){
  200. _t.tableData[_t.rowIndex] = parames
  201. console.log("修改成功")
  202. location.reload();
  203. }else{
  204. this.$message.error("修改失败")
  205. }
  206. this.menuDialogShow = false
  207. this.isloading = false
  208. })
  209. }else{
  210. this.$api.authority.addMenu(parames).then(res=>{
  211. _t.loadingFlag = false;
  212. if(res.code==200){
  213. console.log("创建成功")
  214. location.reload();
  215. }else{
  216. this.$message.error(res.message)
  217. }
  218. this.menuDialogShow = false
  219. this.isloading = false
  220. })
  221. }
  222. },
  223. //删除菜单
  224. deleteAuthority(row, index) {
  225. this.MenuId = row.id
  226. this.MenuRowIndex = index
  227. this.DialogShow = true
  228. },
  229. submitSureClickDel(row,index){
  230. let parames = {
  231. 'id':this.MenuId
  232. }
  233. this.$api.authority.delMenu(parames).then(res=>{
  234. if(res.code==200){
  235. this.DialogShow = false
  236. this.getList()
  237. }else{
  238. this.$message.error("查询失败")
  239. }
  240. })
  241. }
  242. },
  243. created() {
  244. this.getList();
  245. }
  246. }
  247. </script>