cbcab448d6c86f2001e69de900735dad792aaaf1.svn-base 16 KB

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