feb2db960637c5e3c57f494bfce16e751ac93fbb.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <div class="app-container">
  3. <div class="app-container">
  4. <div class="filter-container">
  5. <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate"> 新增 </el-button>
  6. </div>
  7. <el-table
  8. v-loading="listLoading"
  9. element-loading-text="给我一点时间"
  10. :data="list"
  11. border
  12. fit
  13. highlight-current-row
  14. style="width: 100%;"
  15. :row-style="rowStyle"
  16. :cell-style="cellStyle"
  17. class="elTable"
  18. row-key="id"
  19. default-expand-all
  20. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  21. >
  22. <el-table-column
  23. label="角色名称"
  24. header-align="center"
  25. min-width="150px"
  26. align="center"
  27. >
  28. <template slot-scope="scope">
  29. <span>{{ scope.row.name }}</span>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="顺序" min-width="80px" header-align="center" align="center">
  33. <template slot-scope="scope">
  34. <span>{{ scope.row.sort }}</span>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="启用" min-width="80px" header-align="center" align="center">
  38. <template slot-scope="scope">
  39. <el-switch
  40. v-model="scope.row.enable"
  41. active-color="#13ce66"
  42. inactive-color="#ff4949"
  43. :active-value="1"
  44. :inactive-value="0"
  45. @change="handleEnableChange(scope.$index, scope.row)"
  46. />
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="操作" header-align="center" align="center" width="200" class-name="small-padding fixed-width" fixed="right">
  50. <template slot-scope="{row}">
  51. <el-button type="warning" size="mini" @click="handleMenu(row)">菜单</el-button>
  52. <el-button type="warning" size="mini" style="width:70px" @click="handleDataRole(row)">数据权限</el-button>
  53. <el-button type="primary" size="mini" @click="handleUpdate(row)">编辑</el-button>
  54. <el-button v-if="row.status!='已删'" size="mini" type="danger" @click="handleDelete(row)">删除</el-button>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <pagination v-show="total>=0" :total="total" :page.sync="getdataListParm.offset" :limit.sync="getdataListParm.pagecount" @pagination="getList" />
  59. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
  60. <el-form ref="dataForm" :rules="rules" :model="dataform" label-position="left" label-width="100px" style="width: 600px; margin-left:50px;">
  61. <el-form-item label="角色名称" prop="name">
  62. <el-input
  63. ref="name"
  64. v-model="dataform.name"
  65. />
  66. </el-form-item>
  67. <el-form-item label="顺序" prop="sort">
  68. <el-input
  69. ref="sort"
  70. v-model="dataform.sort"
  71. />
  72. </el-form-item>
  73. <el-form-item label="启用" prop="enable">
  74. <el-switch
  75. ref="enable"
  76. v-model="dataform.enable"
  77. active-color="#13ce66"
  78. inactive-color="#ff4949"
  79. :active-value="1"
  80. :inactive-value="0"
  81. />
  82. </el-form-item>
  83. </el-form>
  84. <div slot="footer" class="dialog-footer">
  85. <el-button v-if="dialogStatus==='create'" ref="createb" class="save" @click="createData_again()"> 确认新增 </el-button>
  86. <el-button class="save" @click="dialogStatus==='create'?createData():updateData()"> 确认 </el-button>
  87. <el-button class="minCancel" @click="dialogFormVisible = false"> 关闭 </el-button>
  88. </div>
  89. </el-dialog>
  90. <el-dialog :title="textMap['dataRole']" :visible.sync="dialogDataRoleVisible" :close-on-click-modal="false">
  91. <el-form ref="dataRoleTemp" :rules="rules" label-position="left" :model="dataRoleTemp" label-width="100px" style="width: 600px; margin-left:50px;">
  92. <el-form-item label="数据权限" prop="datarole">
  93. <el-radio-group v-model="dataRoleTemp.datarole">
  94. <el-radio :label="3">全部数据</el-radio>
  95. <el-radio :label="2">牧场数据</el-radio>
  96. <el-radio :label="1">部门数据</el-radio>
  97. <el-radio :label="0">个人数据</el-radio>
  98. </el-radio-group>
  99. </el-form-item>
  100. </el-form>
  101. <div slot="footer" class="dialog-footer">
  102. <el-button class="save" @click="updateDataRole()"> 确认 </el-button>
  103. <el-button class="minCancel" @click="dialogDataRoleVisible = false"> 关闭 </el-button>
  104. </div>
  105. </el-dialog>
  106. <el-dialog :title="textMap['menu']" :visible.sync="dialogMenuVisible" :close-on-click-modal="false">
  107. <el-form :rules="rules" label-position="left" label-width="100px" style="width: 600px; margin-left:50px;">
  108. <el-form-item label="菜单" prop="menuname">
  109. <tree-select
  110. :disabled="disabled"
  111. :height="280"
  112. :width="200"
  113. size="small"
  114. multiple
  115. :data="parentMenu"
  116. :default-props="defaultProps"
  117. collapse-tags
  118. check-strictly
  119. :node-key="nodeKey"
  120. :checked-keys="defaultCheckedKeys"
  121. @popoverHide="popoverHide"
  122. />
  123. </el-form-item>
  124. </el-form>
  125. <div slot="footer" class="dialog-footer">
  126. <el-button class="save" :disabled="isokDisable" @click="updateMenu()"> 确认 </el-button>
  127. <el-button class="minCancel" @click="dialogMenuVisible = false"> 关闭 </el-button>
  128. </div>
  129. </el-dialog>
  130. </div>
  131. </div>
  132. </template>
  133. <script>
  134. import TreeSelect from '@/components/TreeSelect'
  135. import waves from '@/directive/waves' // waves directive
  136. import { isIntegerZero } from '@/utils/validate'
  137. import { PostDataByName, GetDataByName, UpdateDataRelation, getRecuData, failproccess } from '@/api/common'
  138. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  139. import { MessageBox } from 'element-ui'
  140. import Cookies from 'js-cookie'
  141. export default {
  142. name: 'Role',
  143. components: { Pagination, TreeSelect },
  144. directives: { waves },
  145. data() {
  146. return {
  147. disabled: false,
  148. tableKey: 0,
  149. list: [{ 'sqlname': '', 'id': 0, 'sqlstr': '' }],
  150. parentMenu: [],
  151. total: 0,
  152. listLoading: true,
  153. requestParam: {
  154. name: 'createRole',
  155. offset: 0,
  156. pagecount: 0,
  157. params: []
  158. },
  159. UpdateDataRelationParam: {
  160. name: '',
  161. dataname: '',
  162. datavalue: '',
  163. valuename: '',
  164. values: ''
  165. },
  166. dataform: {
  167. id: '',
  168. name: '',
  169. selectMenus: [],
  170. sort: '',
  171. enable: ''
  172. },
  173. getdataListParm: { name: 'getRoleall',
  174. offset: 1,
  175. pagecount: 10,
  176. returntype: 'Map',
  177. parammaps: { pastureid: Cookies.get('pastureid') }},
  178. getMenuParm: { name: 'getMenuandButtonRecuRule',
  179. idname: 'id',
  180. params: [-1] },
  181. rules: {
  182. name: [{ type: 'string', required: true, message: '名称必填', trigger: 'change' }],
  183. sort: [{ validator: isIntegerZero, trigger: 'blur' }],
  184. datarole: [{ required: true, message: '必填', trigger: 'blur' }]
  185. },
  186. dialogFormVisible: false,
  187. dialogMenuVisible: false,
  188. dialogDataRoleVisible: false,
  189. selectedMenu: '',
  190. dialogStatus: '',
  191. textMap: {
  192. update: '编辑',
  193. create: '新增',
  194. menu: '授权菜单',
  195. dataRole: '数据权限'
  196. },
  197. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  198. cellStyle: { padding: 0 + 'px' },
  199. defaultProps: {
  200. children: 'children',
  201. label: 'title'
  202. },
  203. nodeKey: 'id',
  204. defaultCheckedKeys: [],
  205. getDataRoleListParm: {
  206. name: 'getDataRole',
  207. offset: 1,
  208. pagecount: 10,
  209. returntype: 'Map',
  210. parammaps: {}
  211. },
  212. isokDisable: false,
  213. dataRoleTemp: {},
  214. dataRolelist: []
  215. }
  216. },
  217. created() {
  218. this.getList()
  219. },
  220. methods: {
  221. popoverHide(checkedIds, checkedData) {
  222. this.dataform.selectMenus = checkedIds
  223. this.selectedMenu = checkedIds
  224. this.UpdateDataRelationParam.values = checkedIds
  225. },
  226. getMenuList() {
  227. getRecuData(this.getMenuParm).then(response => {
  228. this.parentMenu = response.data
  229. })
  230. },
  231. getList() {
  232. this.listLoading = true
  233. GetDataByName(this.getdataListParm).then(response => {
  234. if (response.data.list !== null) {
  235. for (var i = 0; i < response.data.list.length; i++) {
  236. response.data.list[i].enable = parseInt(response.data.list[i].enable)
  237. }
  238. this.list = response.data.list
  239. }
  240. this.total = response.data.total
  241. this.getMenuList()
  242. setTimeout(() => {
  243. this.listLoading = false
  244. }, 0.5 * 1000)
  245. })
  246. },
  247. resetRequestParam() {
  248. this.dataform.id = ''
  249. this.dataform.name = ''
  250. this.dataform.sort = '0'
  251. this.dataform.enable = '1'
  252. },
  253. handleCreate() {
  254. this.resetRequestParam()
  255. this.dialogStatus = 'create'
  256. this.dialogFormVisible = true
  257. this.$nextTick(() => {
  258. this.$refs['dataForm'].clearValidate()
  259. this.$refs.name.focus()
  260. })
  261. },
  262. createData() {
  263. this.$refs['dataForm'].validate((valid) => {
  264. if (valid) {
  265. this.requestParam.name = 'createRole'
  266. this.requestParam.params = []
  267. this.requestParam.params[0] = this.dataform.name
  268. this.requestParam.params[1] = this.dataform.sort
  269. this.requestParam.params[2] = this.dataform.enable
  270. PostDataByName(this.requestParam).then(() => {
  271. this.getList()
  272. this.dialogFormVisible = false
  273. this.$notify({
  274. title: '成功',
  275. message: '新增成功',
  276. type: 'success',
  277. duration: 2000
  278. })
  279. })
  280. }
  281. })
  282. },
  283. createData_again() {
  284. this.$refs['dataForm'].validate((valid) => {
  285. if (valid) {
  286. this.requestParam.name = 'createRole'
  287. this.requestParam.params = []
  288. this.requestParam.params[0] = this.dataform.name
  289. this.requestParam.params[1] = this.dataform.sort
  290. this.requestParam.params[2] = this.dataform.enable
  291. PostDataByName(this.requestParam).then(() => {
  292. this.$nextTick(() => {
  293. this.$refs['name'].focus()
  294. })
  295. this.getList()
  296. this.resetRequestParam()
  297. this.$notify({
  298. title: '成功',
  299. message: '新增成功',
  300. type: 'success',
  301. duration: 2000
  302. })
  303. })
  304. }
  305. })
  306. },
  307. handleMenu(row) {
  308. this.requestParam.name = 'getMenuByRole'
  309. this.requestParam.params = []
  310. this.requestParam.params[0] = row.id
  311. this.requestParam.pagecount = 0
  312. this.requestParam.returntype = 'list'
  313. this.dataform.id = row.id
  314. this.dialogMenuVisible = true
  315. GetDataByName(this.requestParam).then(response => {
  316. this.selectedMenu = response.data.lists.menu_id
  317. this.defaultCheckedKeys = this.selectedMenu
  318. this.UpdateDataRelationParam.values = this.defaultCheckedKeys
  319. })
  320. },
  321. updateMenu() {
  322. this.isokDisable = true
  323. setTimeout(() => {
  324. this.isokDisable = false
  325. }, 1000)
  326. this.UpdateDataRelationParam.name = 'role_menu'
  327. this.UpdateDataRelationParam.dataname = 'role_id'
  328. this.UpdateDataRelationParam.datavalue = this.dataform.id
  329. this.UpdateDataRelationParam.valuename = 'menu_id'
  330. this.UpdateDataRelationParam.values = this.selectedMenu
  331. UpdateDataRelation(this.UpdateDataRelationParam).then(() => {
  332. this.dialogMenuVisible = false
  333. this.$notify({
  334. title: '成功',
  335. message: '修改成功',
  336. type: 'success',
  337. duration: 2000
  338. })
  339. })
  340. },
  341. handleUpdate(row) {
  342. this.dataform.id = row.id
  343. this.dataform.name = row.name
  344. this.dataform.sort = row.sort
  345. this.dataform.enable = row.enable
  346. this.dialogStatus = 'update'
  347. this.dialogFormVisible = true
  348. this.$nextTick(() => {
  349. this.$refs['dataForm'].clearValidate()
  350. this.$refs.name.focus()
  351. })
  352. },
  353. updateData() {
  354. this.$refs['dataForm'].validate((valid) => {
  355. if (valid) {
  356. this.requestParam.name = 'updateRole'
  357. this.requestParam.params = []
  358. this.requestParam.params[0] = this.dataform.name
  359. this.requestParam.params[1] = this.dataform.sort
  360. this.requestParam.params[2] = this.dataform.enable
  361. this.requestParam.params[3] = this.dataform.id
  362. PostDataByName(this.requestParam).then(() => {
  363. this.getList()
  364. this.resetRequestParam()
  365. this.dialogFormVisible = false
  366. this.$notify({
  367. title: '成功',
  368. message: '修改成功',
  369. type: 'success',
  370. duration: 2000
  371. })
  372. })
  373. }
  374. })
  375. },
  376. handleEnableChange(index, row) {
  377. this.requestParam.name = 'updateRole'
  378. this.requestParam.params = []
  379. this.requestParam.params[0] = row.name
  380. this.requestParam.params[1] = row.sort
  381. this.requestParam.params[2] = row.enable
  382. this.requestParam.params[3] = row.id
  383. PostDataByName(this.requestParam).then(() => {
  384. this.$notify({
  385. title: '成功',
  386. message: '修改成功',
  387. type: 'success',
  388. duration: 2000
  389. })
  390. })
  391. },
  392. handleDelete(row) {
  393. MessageBox.confirm('名称:' + row.name, '确认删除?', {
  394. confirmButtonText: '确认',
  395. cancelButtonText: '取消',
  396. type: 'warning'
  397. }).then(() => {
  398. this.requestParam.name = 'deleteRole'
  399. this.requestParam.params = []
  400. this.requestParam.params[0] = row.id
  401. PostDataByName(this.requestParam).then(() => {
  402. this.getList()
  403. this.resetRequestParam()
  404. this.dialogFormVisible = false
  405. this.$notify({
  406. title: '成功',
  407. message: '删除成功',
  408. type: 'success',
  409. duration: 2000
  410. })
  411. })
  412. })
  413. },
  414. handleDataRole(row) {
  415. this.dataRoleTemp = Object.assign({}, row)
  416. this.$set(this.dataRoleTemp, 'datarole', 0)
  417. this.dialogDataRoleVisible = true
  418. this.getDataRoleListParm.parammaps.id = row.id
  419. GetDataByName(this.getDataRoleListParm).then(response => {
  420. this.dataRolelist = response.data.list
  421. this.dataRoleTemp.datarole = response.data.list[0].datarole
  422. this.$forceUpdate()
  423. })
  424. },
  425. updateDataRole() {
  426. this.isokDisable = true
  427. setTimeout(() => {
  428. this.isokDisable = false
  429. }, 1000)
  430. this.$refs['dataRoleTemp'].validate((valid) => {
  431. if (valid) {
  432. this.requestParam.name = 'setDataRole'
  433. this.requestParam.parammaps = {}
  434. this.requestParam.parammaps.id = this.dataRoleTemp.id
  435. this.requestParam.parammaps.datarole = this.dataRoleTemp.datarole
  436. PostDataByName(this.requestParam).then(response => {
  437. console.log('设置数据权限保存发送参数', this.requestParam)
  438. if (response.msg !== 'fail') {
  439. this.getList()
  440. this.dialogDataRoleVisible = false
  441. this.$notify({
  442. title: '成功',
  443. message: '设置成功',
  444. type: 'success',
  445. duration: 2000
  446. })
  447. } else {
  448. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  449. }
  450. })
  451. }
  452. })
  453. }
  454. }
  455. }
  456. </script>