module.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <template>
  2. <div>
  3. <el-card class="box-card" style="height: calc(100vh - 92px);">
  4. <div slot="header" style="height: 20px;">
  5. <span style="float: left;">
  6. <i class="icon icon-table2"></i>
  7. </span>
  8. <el-breadcrumb class="heading" style="float: left; margin-left: 5px">
  9. <el-breadcrumb-item :to="{ path: '/' }">平台首页</el-breadcrumb-item>
  10. <el-breadcrumb-item :to="{ path: '/system/module' }">菜单管理</el-breadcrumb-item>
  11. </el-breadcrumb>
  12. <span style="float: right;">
  13. <el-button size="mini" type="primary" style="margin-left:10px; margin-top: -4px;" @click="opendatadialog(1,null,-1);resetForm('moduleform')">新增菜单</el-button>
  14. </span>
  15. <el-form ref="form" :inline="true" style="float: right; margin-top: -10px">
  16. <el-form-item label="菜单名称">
  17. <el-input size="mini" style="width: 165px;" v-model="keyword" placeholder="请输入菜单名称"></el-input>
  18. </el-form-item>
  19. <el-form-item>
  20. <el-dropdown split-button type="primary" size="mini" @click="seachdata" @command="searchCommand">
  21. 查询
  22. <el-dropdown-menu slot="dropdown">
  23. <!-- <el-dropdown-item command="search">高级查询</el-dropdown-item> -->
  24. <el-dropdown-item command="clear">查询重置</el-dropdown-item>
  25. </el-dropdown-menu>
  26. </el-dropdown>
  27. </el-form-item>
  28. </el-form>
  29. </div>
  30. <el-row :gutter="20">
  31. <el-col :span="6">
  32. <el-tree highlight-current="true" :expand-on-click-node="true" node-key="id" :data="moduletreelist" :props="orgtreeprops" :default-expanded-keys="userdepartment"
  33. @node-click="orgtreeNodeClick" ref="orgmanagetree">
  34. </el-tree>
  35. </el-col>
  36. <el-col :span="18">
  37. <el-table :data="tablelist" border>
  38. <el-table-column label="操作" width="70" align="center">
  39. <template slot-scope="scope">
  40. <template v-if="scope.row.Parentid !== 0">
  41. <el-button size="small" type="text" @click="opendatadialog(2,scope.row,scope.$index);resetForm('moduleform')" icon="el-icon-edit"
  42. title="编辑"></el-button>
  43. <el-button size="small" type="text" @click="deletedata(scope.row)" icon="el-icon-delete" title="删除" style="margin-left: 3px"></el-button>
  44. <!--暂时隐藏-->
  45. <el-button v-if="1==2" size="small" type="success" @click="permission(scope.row)">权限</el-button>
  46. </template>
  47. </template>
  48. </el-table-column>
  49. <el-table-column prop="Fullname" align="center" label="菜单名称" show-overflow-tooltip></el-table-column>
  50. <el-table-column prop="Parentname" align="center" label="上级菜单" show-overflow-tooltip></el-table-column>
  51. <el-table-column prop="NavigateUrl" align="center" label="菜单地址" show-overflow-tooltip></el-table-column>
  52. <el-table-column prop="ImageIndex" align="center" label="菜单图标" show-overflow-tooltip></el-table-column>
  53. </el-table>
  54. </el-col>
  55. </el-row>
  56. <!--分页-->
  57. <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 15, 20, 25]"
  58. :page-size="size" layout="total, sizes, prev, pager, next, jumper" :total="currentItemCount">
  59. </el-pagination>
  60. </el-card>
  61. <!--新增、编辑组织信息-->
  62. <el-dialog :title="dialogtitle" :visible.sync="datadialogVisible" top="5vh">
  63. <el-form :model="moduleform" :rules="rulesorganize" ref="moduleform">
  64. <el-form-item label="上级菜单" label-width="120px" required>
  65. <el-cascader :options="moduletreelist" :props="orgtreeprops" change-on-select :show-all-levels="false" v-model="selectedorg"
  66. placeholder="请选择菜单"></el-cascader>
  67. </el-form-item>
  68. <el-form-item label="菜单名称" prop="fullname" label-width="120px">
  69. <el-input v-model="moduleform.fullname" auto-complete="off"></el-input>
  70. </el-form-item>
  71. <el-form-item label="菜单地址" prop="NavigateUrl" label-width="120px">
  72. <el-input v-model="moduleform.NavigateUrl" auto-complete="off"></el-input>
  73. </el-form-item>
  74. <el-form-item label="菜单图标" prop="ImageIndex" label-width="120px">
  75. <el-input v-model="moduleform.ImageIndex" auto-complete="off"></el-input>
  76. </el-form-item>
  77. </el-form>
  78. <div slot="footer" class="dialog-footer">
  79. <el-button @click="datadialogVisible = false">取 消</el-button>
  80. <el-button type="primary" @click="savedata('moduleform')">确 定</el-button>
  81. </div>
  82. </el-dialog>
  83. <el-dialog :title="permissiondialogtitle" :visible.sync="permissiondatadialogVisible" top="5vh">
  84. <el-form ref="alertform">
  85. <el-form-item>
  86. <div style="margin-left:1px;border:1px #CCCCCC solid;overflow:auto;height:300px;">
  87. <el-checkbox-group v-model="binddevices">
  88. <el-checkbox v-for="item in devices" :label="item.Id" :key="item.Id" style="margin-left:15px;">{{item.Code}}</el-checkbox>
  89. </el-checkbox-group>
  90. </div>
  91. <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" style="margin-left:15px;">全选</el-checkbox>
  92. </el-form-item>
  93. </el-form>
  94. <div slot="footer" class="dialog-footer" style="margin-top:-35px;">
  95. <el-button @click="permissiondatadialogVisible = false">取 消</el-button>
  96. <el-button type="primary" @click="savepermission()">确 定</el-button>
  97. </div>
  98. </el-dialog>
  99. </div>
  100. </template>
  101. <script>
  102. import {
  103. mapGetters
  104. } from 'vuex'
  105. export default {
  106. name: 'organize',
  107. data() {
  108. return {
  109. downloading: true,
  110. selectedNode: 0,
  111. currentItemCount: 0,
  112. currentPage: 1,
  113. size: 10,
  114. tablelist: [], // 处理分页用
  115. keyword: '',
  116. parentid: '',
  117. datadialogVisible: false,
  118. dialogtitle: '',
  119. moduleform: {
  120. parentid: 0,
  121. fullname: '',
  122. description: '',
  123. NavigateUrl:'',
  124. ImageIndex:'',
  125. id: 0
  126. },
  127. rulesorganize: {
  128. fullname: [{
  129. required: true,
  130. message: '请输入菜单名称',
  131. trigger: 'blur'
  132. }]
  133. },
  134. operatingitem: 0,
  135. permissiondialogtitle: '',
  136. permissiondatadialogVisible: false,
  137. binddevices: [],
  138. devices: [],
  139. devicesallid: [],
  140. isIndeterminate: true,
  141. checkAll: false,
  142. update: true,
  143. childArr: [],
  144. parentArr: [],
  145. // 级联选项
  146. options: [],
  147. currentOrgan: '请选择菜单',
  148. havechild: false,
  149. // 数据传输
  150. currId: 0,
  151. currOrganName: '',
  152. moduletreelist: [],
  153. orgtreeprops: {
  154. value: 'id',
  155. label: 'Fullname',
  156. children: 'children'
  157. },
  158. selectedorg: [],
  159. userdepartment: []
  160. }
  161. },
  162. created() {
  163. // initial data
  164. this.initData()
  165. this.getmoduletreelist()
  166. },
  167. updated() {},
  168. watch: {},
  169. computed: mapGetters({
  170. authUser: 'authUser'
  171. }),
  172. methods: {
  173. initData() {
  174. let _this = this
  175. // paginate
  176. let params = {
  177. _currentPage: this.currentPage,
  178. _size: this.size,
  179. keyword: this.keyword,
  180. parentid: this.parentid,
  181. }
  182. // request
  183. this.$axios.get('/module/listbandparentname', {
  184. params
  185. })
  186. .then(res => {
  187. console.log("======res.data.items1=====",res.data.items)
  188. // response
  189. _this.tablelist = res.data.items
  190. _this.currentItemCount = res.data.currentItemCount
  191. _this.downloading = false
  192. })
  193. .catch(err => {
  194. // handle error
  195. console.error(err)
  196. })
  197. },
  198. getmoduletreelist() {
  199. let _this = this
  200. // request
  201. _this.$axios.get('/module/list', {
  202. })
  203. .then(res => {
  204. console.log("======res.data.items2=====",res.data.items)
  205. _this.moduletreelist = window.toolfun_gettreejson(res.data.items, 'Id', 'Parentid', 'Id,Fullname')
  206. })
  207. .catch(err => {
  208. // handle error
  209. console.error(err)
  210. })
  211. },
  212. orgtreeNodeClick(data) {
  213. this.parentid = data.id + ''
  214. this.currentPage = 1
  215. this.initData()
  216. },
  217. seachdata() {
  218. this.currentPage = 1
  219. this.initData()
  220. },
  221. permission(v) {
  222. this.binddevices = []
  223. this.permissiondialogtitle = '权限设置'
  224. this.permissiondatadialogVisible = true
  225. this.currId = v.Id
  226. this.currOrganName = v.Fullname
  227. this.$axios.get('/equipment/bindequipment/' + this.currId, null)
  228. .then(res => {
  229. // response
  230. for (var i = 0; i < res.data.items.length; i++) {
  231. this.binddevices.push(res.data.items[i].Id)
  232. }
  233. })
  234. .catch(err => {
  235. // handle error
  236. console.error(err)
  237. })
  238. },
  239. savepermission() {
  240. let _this = this
  241. _this.$axios.put('/equipment/permission/' + this.currId, {
  242. EquipmentIds: this.binddevices + '',
  243. OrganizeName: this.currOrganName
  244. })
  245. .then(res => {
  246. // response
  247. if (res.data.code === 0) {
  248. _this.$message({
  249. type: 'success',
  250. message: res.data.message
  251. })
  252. _this.permissiondatadialogVisible = false
  253. } else {
  254. _this.$message({
  255. type: 'warning',
  256. message: res.data.message
  257. })
  258. }
  259. })
  260. .catch(() => {})
  261. },
  262. handleSizeChange(value) {
  263. this.size = value
  264. this.currentPage = 1
  265. this.initData()
  266. },
  267. handleCurrentChange(value) {
  268. this.currentPage = value
  269. this.initData()
  270. },
  271. jstimehandle(val) {
  272. val = val.replace('T', ' ')
  273. return val.substring(0, 19)
  274. },
  275. opendatadialog(item, v, index) {
  276. this.operatingitem = item
  277. this.datadialogVisible = true
  278. this.clearorganizeform()
  279. let _this = this
  280. if (item === 1) {
  281. _this.dialogtitle = `新增菜单`
  282. if (this.parentid !== '') {
  283. this.$axios.get('/module/parentlist/' + this.parentid, {})
  284. .then(res => {
  285. if (res.data.code === 0) {
  286. // 选中状态
  287. _this.selectedorg = []
  288. let pidarr = res.data.message.split(',')
  289. for (var i = pidarr.length - 1; i >= 0; i--) {
  290. if (pidarr[i] !== '0') {
  291. _this.selectedorg.push(parseInt(pidarr[i]))
  292. }
  293. }
  294. } else {
  295. _this.$message({
  296. type: 'warning',
  297. message: '出现错误!'
  298. })
  299. this.datadialogVisible = false
  300. }
  301. })
  302. .catch(err => {
  303. // handle error
  304. console.error(err)
  305. })
  306. }
  307. } else if (item === 2) {
  308. this.$axios.get('/module/parentlist/' + v.Parentid, {})
  309. .then(res => {
  310. if (res.data.code === 0) {
  311. _this.dialogtitle = `编辑菜单信息(${v.Fullname})`
  312. _this.moduleform.parentid = v.Parentid
  313. _this.moduleform.fullname = v.Fullname
  314. _this.moduleform.description = v.Description
  315. _this.moduleform.id = v.Id
  316. _this.moduleform.NavigateUrl = v.NavigateUrl
  317. _this.moduleform.ImageIndex =v.ImageIndex
  318. _this.selectedorg.push(parseInt(v.Parentid))
  319. } else {
  320. _this.$message({
  321. type: 'warning',
  322. message: '出现错误!'
  323. })
  324. this.datadialogVisible = false
  325. }
  326. })
  327. .catch(err => {
  328. // handle error
  329. console.error(err)
  330. })
  331. }
  332. },
  333. savedata(formName) {
  334. let _this = this
  335. this.$refs[formName].validate((valid) => {
  336. if (valid) {
  337. _this.moduleform.parentid = parseInt(_this.selectedorg[_this.selectedorg.length - 1])
  338. if (_this.moduleform.parentid === 0) {
  339. _this.$message({
  340. type: 'warning',
  341. message: '请选择上一级组织!'
  342. })
  343. return
  344. }
  345. if (_this.moduleform.parentid === _this.moduleform.id) {
  346. _this.$message({
  347. type: 'warning',
  348. message: '上一级组织不能为自身数据!'
  349. })
  350. return
  351. }
  352. if (_this.operatingitem === 1) {
  353. _this.$axios.post('module/', _this.moduleform)
  354. .then(res => {
  355. // response
  356. if (res.data.code === 0) {
  357. _this.$message({
  358. type: 'success',
  359. message: res.data.message
  360. })
  361. _this.datadialogVisible = false
  362. this.initData()
  363. // 重新加载tree数据
  364. _this.getmoduletreelist()
  365. } else {
  366. _this.$message({
  367. type: 'warning',
  368. message: res.data.message
  369. })
  370. }
  371. })
  372. .catch(err => {
  373. // handle error
  374. console.error(err)
  375. })
  376. } else if (_this.operatingitem === 2) {
  377. _this.$axios.put('module/' + _this.moduleform.id, _this.moduleform)
  378. .then(res => {
  379. // response
  380. if (res.data.code === 0) {
  381. _this.$message({
  382. type: 'success',
  383. message: res.data.message
  384. })
  385. _this.datadialogVisible = false
  386. // 更新界面
  387. _this.initData()
  388. // 重新加载tree数据
  389. _this.getmoduletreelist()
  390. } else {
  391. _this.$message({
  392. type: 'warning',
  393. message: res.data.message
  394. })
  395. }
  396. })
  397. .catch(() => {})
  398. }
  399. } else {
  400. return false
  401. }
  402. })
  403. },
  404. deletedata(val) {
  405. let _this = this
  406. _this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
  407. confirmButtonText: '确定',
  408. cancelButtonText: '取消',
  409. type: 'warning'
  410. }).then(() => {
  411. _this.$axios.delete('module/' + val.Id, null)
  412. .then(res => {
  413. // response
  414. if (res.data.code === 0) {
  415. _this.$message({
  416. type: 'success',
  417. message: res.data.message
  418. })
  419. // 更新界面
  420. _this.initData()
  421. // 重新加载tree数据
  422. _this.getmoduletreelist()
  423. } else {
  424. _this.$message({
  425. type: 'warning',
  426. message: res.data.message
  427. })
  428. }
  429. })
  430. .catch(() => {})
  431. }).catch(() => {})
  432. },
  433. resetForm(formName) {
  434. //this.$refs[formName].resetFields()
  435. },
  436. clearorganizeform() {
  437. this.moduleform = {
  438. parentid: 0,
  439. fullname: '',
  440. description: '',
  441. NavigateUrl:'',
  442. ImageIndex:'',
  443. id: 0
  444. }
  445. },
  446. searchCommand(command) {
  447. if (command == 'clear') {
  448. this.clearSearch()
  449. }
  450. },
  451. clearSearch() {
  452. this.keyword = ''
  453. this.initData()
  454. }
  455. }
  456. }
  457. </script>
  458. <style lang="scss">
  459. .el-pagination {
  460. margin: 1rem 0 2rem;
  461. text-align: right;
  462. }
  463. .triggerone {
  464. font-size: 13px;
  465. margin-left: 80px;
  466. }
  467. .plab {
  468. font-size: 13px;
  469. color: #999;
  470. }
  471. </style>