cf888a0a65c30901f0f8fddc9a7737f0077df9c7.svn-base 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. <template>
  2. <div class="app-container">
  3. <div class="search">
  4. <el-input v-model="table.getdataListParm.parammaps.rolename" placeholder="角色名称" style="width: 180px;" class="filter-item" clearable />
  5. <el-input v-model="table.getdataListParm.parammaps.createmp" placeholder="创建人" style="width: 180px;" class="filter-item" clearable />
  6. <el-select v-model="table.getdataListParm.parammaps.enable" placeholder="是否启用" class="filter-item" style="width: 120px;" clearable>
  7. <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.id" />
  8. </el-select>
  9. <el-date-picker ref="inputDatetime" v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
  10. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  11. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  12. </div>
  13. <div class="operation">
  14. <el-button v-if="isRoleEdit" icon="el-icon-plus" class="success" @click="handleCreate">新增</el-button>
  15. <el-button v-if="isRoleEdit" icon="el-icon-delete" class="danger" @click="handleDelete">删除</el-button>
  16. </div>
  17. <div class="table">
  18. <el-table
  19. :key="table.tableKey"
  20. v-loading="table.listLoading"
  21. element-loading-text="给我一点时间"
  22. :data="table.list"
  23. border
  24. fit
  25. highlight-current-row
  26. style="width: 100%;"
  27. :row-style="rowStyle"
  28. :cell-style="cellStyle"
  29. class="elTable table-fixed"
  30. @selection-change="handleSelectionChange"
  31. >
  32. <el-table-column type="selection" align="center" width="50" />
  33. <el-table-column label="序号" align="center" type="index" width="50px">
  34. <template slot-scope="scope">
  35. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="角色名称" min-width="130px" align="center">
  39. <template slot-scope="scope">
  40. <span v-if="scope.row.NoEdit">{{ scope.row.rolename }}</span>
  41. <el-input v-if="scope.row.Edit" v-model="scope.row.rolename" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="备注" min-width="130px" align="center">
  45. <template slot-scope="scope">
  46. <span v-if="scope.row.NoEdit">{{ scope.row.remark }}</span>
  47. <el-input v-if="scope.row.Edit" v-model="scope.row.remark" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="创建时间" min-width="150px" align="center">
  51. <template slot-scope="scope">
  52. <span>{{ scope.row.createdtime }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="创建人" min-width="150px" align="center">
  56. <template slot-scope="scope">
  57. <span>{{ scope.row.createmp }}</span>
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="是否启用" min-width="110px" align="center">
  61. <template slot-scope="scope">
  62. <el-switch v-model="scope.row.enable" :disabled="scope.row.NoEdit==true" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="handleEnableChange(scope.$index, scope.row)" />
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="操作" align="center" width="180" class-name="small-padding fixed-width" fixed="right">
  66. <template slot-scope="{row}">
  67. <!-- 页面权限 -->
  68. <a v-if="row.NoEdit && isRoleEdit" class="correcting" @click="handleRole(row)">页面权限</a>
  69. <span v-if="row.NoEdit && isRoleEdit" class="centerSpan">|</span>
  70. <!-- 新增 -->
  71. <el-button v-if="row.isCreate && isRoleEdit" icon="el-icon-folder-checked" class="miniSuccess" :disabled="isokDisable" @click="createData(row)" />
  72. <span v-if="row.isCreate && isRoleEdit" class="centerSpan">|</span>
  73. <el-button v-if="row.isCreate && isRoleEdit" icon="el-icon-close" class="minCancel" @click="createCancel(row)" />
  74. <!-- 编辑 -->
  75. <el-button v-if="row.isUpdate && isRoleEdit" icon="el-icon-edit-outline" class="miniSuccess" @click="handleUpdate(row)" />
  76. <span v-if="row.isUpdate && isRoleEdit" class="centerSpan">|</span>
  77. <el-button v-if="row.isUpdate && isRoleEdit" icon="el-icon-delete" class="miniDanger" @click="handleRowDelete(row)" />
  78. <!-- 编辑保存 -->
  79. <el-button v-if="row.isUpdateSave && isRoleEdit" icon="el-icon-folder-checked" class="miniSuccess" :disabled="isokDisable" @click="updateData(row)" />
  80. <span v-if="row.isUpdateSave && isRoleEdit" class="centerSpan">|</span>
  81. <el-button v-if="row.isUpdateSave && isRoleEdit" icon="el-icon-close" class="minCancel" @click="updateCancel(row)" />
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  86. </div>
  87. <el-dialog :fullscreen="dialogFull" :visible.sync="role.dialogFormVisible" :close-on-click-modal="false" width="70%">
  88. <template slot="title">
  89. <div class="avue-crud__dialog__header">
  90. <span class="el-dialog__title">
  91. <span style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px" />
  92. {{ textMap[role.dialogStatus] }}
  93. </span>
  94. <div class="avue-crud__dialog__menu" @click="dialogFull? dialogFull=false: dialogFull=true">
  95. <svg-icon v-if="dialogFull" icon-class="exit-fullscreen" />
  96. <svg-icon v-else icon-class="fullscreen" />
  97. </div>
  98. </div>
  99. </template>
  100. <div class="role-details inside-base">
  101. <div class="inside-base-main clearfix">
  102. <div class="inside-base-cont">
  103. <div class="role-cont clearfix">
  104. <div>
  105. <el-table
  106. ref="table"
  107. :data="tableData"
  108. style="width: 100%;margin-bottom: 20px;"
  109. row-key="id"
  110. border
  111. :indent="10"
  112. :select-on-indeterminate="true"
  113. :default-expand-all="false"
  114. show-checkbox
  115. :checked-keys="defaultCheckedKeys"
  116. :tree-props="{children: 'childList', hasChildren: 'hasChildren'}"
  117. >
  118. <el-table-column header-align="center" prop="name" label="页面" />
  119. <el-table-column header-align="center" label="查看" :render-header="renderSeeHeader">
  120. <template slot-scope="scope">
  121. <el-checkbox v-model="scope.row.fnCheck.seebutton" :indeterminate="scope.row.indeterminate.seebutton" label="查看" @change="fnCheckEv(scope, 'seebutton')" />
  122. </template>
  123. </el-table-column>
  124. <el-table-column header-align="center" label="编辑" :render-header="renderEditHeader">
  125. <template slot-scope="scope">
  126. <el-checkbox v-model="scope.row.fnCheck.editbutton" :indeterminate="scope.row.indeterminate.editbutton" label="编辑" @change="fnCheckEv(scope, 'editbutton')" />
  127. </template>
  128. </el-table-column>
  129. </el-table>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. <div slot="footer" class="dialog-footer" style="right:30px;position:absolute;bottom:10px">
  135. <el-button class="cancelClose" @click="role.dialogFormVisible = false;getList(); ">取消</el-button>
  136. <el-button v-if="role.dialogStatus==='role'" class="save" :disabled="isokDisable" @click="roleData()">确认</el-button>
  137. </div>
  138. </div>
  139. </el-dialog>
  140. </div>
  141. </template>
  142. <script>
  143. import { GetDataByName, PostDataByName, failproccess, transData, ExecDataByConfig, checkButtons } from '@/api/common'
  144. import Cookies from 'js-cookie'
  145. import { parseTime } from '@/utils/index.js'
  146. import { MessageBox } from 'element-ui'
  147. import Pagination from '@/components/Pagination'
  148. export default {
  149. name: 'Role',
  150. components: { Pagination },
  151. data() {
  152. return {
  153. dialogFull: false,
  154. isRoleEdit: [],
  155. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }], // 是否启用
  156. table: {
  157. getdataListParm: {
  158. name: 'getRoleList',
  159. page: 1,
  160. offset: 1,
  161. pagecount: parseInt(Cookies.get('pageCount')),
  162. returntype: 'Map',
  163. parammaps: {
  164. pastureid: Cookies.get('pastureid'),
  165. rolename: '',
  166. createmp: '',
  167. enable: '',
  168. startTime: '',
  169. stopTime: '',
  170. inputDatetime: ''
  171. }
  172. },
  173. tableKey: 0,
  174. list: [],
  175. total: 0,
  176. listLoading: true,
  177. temp: {}
  178. },
  179. requestParam: {},
  180. selectList: [],
  181. role: {
  182. dialogFormVisible: false,
  183. dialogStatus: '',
  184. temp: {}
  185. },
  186. // parentType: [],
  187. getRecuListParm: {
  188. name: 'getMenuByRole',
  189. parammaps: {
  190. pastureid: Cookies.get('pastureid')
  191. }
  192. },
  193. tableData: [],
  194. defaultCheckedKeys: [],
  195. // tableData: [
  196. // {
  197. // id: 1, page: '配方计划', pageCheck: false,
  198. // fnList: ['查看', '编辑'],
  199. // fnCheck: { see: false, edit: false },
  200. // childList: [
  201. // { p_id: 1, id: 31, page: '配方模板', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }},
  202. // { p_id: 1, id: 32, page: '栏舍配方', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }}
  203. // ]
  204. // }, {
  205. // id: 2, page: '栏舍生产', pageCheck: false,
  206. // fnList: ['查看', '编辑'],
  207. // fnCheck: { see: false, edit: false },
  208. // childList: [
  209. // { p_id: 2, id: 33, page: '栏舍产奶量', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }},
  210. // { p_id: 2, id: 34, page: '栏舍剩料量', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }}
  211. // ]
  212. // }
  213. // ],
  214. isokDisable: false,
  215. textMap: {
  216. role: '权限管理'
  217. },
  218. rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
  219. cellStyle: { padding: 0 + 'px' }
  220. }
  221. },
  222. created() {
  223. this.getList()
  224. this.getButtons()
  225. },
  226. methods: {
  227. getButtons() {
  228. const Edit = 'Role'
  229. const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
  230. this.isRoleEdit = isRoleEdit
  231. },
  232. getList() {
  233. this.table.listLoading = true
  234. GetDataByName(this.table.getdataListParm).then(response => {
  235. console.log('table数据', response.data.list)
  236. if (response.data.list !== null) {
  237. for (let i = 0; i < response.data.list.length; i++) {
  238. this.$set(response.data.list[i], 'Edit', false) // 编辑
  239. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  240. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  241. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  242. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  243. }
  244. this.table.list = response.data.list
  245. this.table.pageNum = response.data.pageNum
  246. this.table.pageSize = response.data.pageSize
  247. this.table.total = response.data.total
  248. } else {
  249. this.table.list = []
  250. }
  251. setTimeout(() => {
  252. this.table.listLoading = false
  253. }, 100)
  254. })
  255. },
  256. handleEnableChange() {
  257. console.log('点击了是否启用')
  258. },
  259. handleConfirmStartChange() {
  260. console.log('点击了确认开始')
  261. },
  262. handleSearch() {
  263. console.log('点击了查询')
  264. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  265. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  266. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  267. } else {
  268. this.table.getdataListParm.parammaps.inputDatetime = ''
  269. this.table.getdataListParm.parammaps.startTime = ''
  270. this.table.getdataListParm.parammaps.stopTime = ''
  271. }
  272. this.table.getdataListParm.offset = 1
  273. this.getList()
  274. },
  275. handleRefresh() {
  276. console.log('点击了重置')
  277. this.table.getdataListParm.parammaps.rolename = ''
  278. this.table.getdataListParm.parammaps.createmp = ''
  279. this.table.getdataListParm.parammaps.enable = ''
  280. this.table.getdataListParm.parammaps.startTime = ''
  281. this.table.getdataListParm.parammaps.stopTime = ''
  282. this.table.getdataListParm.parammaps.inputDatetime = ''
  283. this.table.getdataListParm.offset = 1
  284. this.getList()
  285. },
  286. handleCreate() {
  287. console.log('点击了新增')
  288. // 编辑true/不可编辑false
  289. // 新增操true,编辑false,编辑保存false
  290. for (let i = 0; i < this.table.list.length; i++) {
  291. if (this.table.list[i].Edit == true) {
  292. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  293. return false
  294. }
  295. }
  296. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'confirmStart': 1, 'createdtime': parseTime(new Date(), '{y}-{m}-{d}'), 'createmp': Cookies.get('employename'), 'rolename': '' })
  297. },
  298. createData(row) {
  299. console.log('点击了新增保存', row)
  300. this.table.temp.pastureid = Cookies.get('pastureid')
  301. this.table.temp.empname = row.empname
  302. this.table.temp.rolename = row.rolename
  303. this.table.temp.enable = row.enable
  304. this.table.temp.remark = row.remark
  305. this.table.temp.createmp = row.createmp
  306. // 检验角色名称/角色是否为空
  307. if (this.table.temp.rolename == '') {
  308. this.$message({ type: 'error', message: '角色名称不能为空', duration: 2000 })
  309. return false
  310. }
  311. this.isokDisable = true
  312. setTimeout(() => {
  313. this.isokDisable = false
  314. }, 1000)
  315. this.requestParam.name = 'createRole'
  316. this.requestParam.parammaps = this.table.temp
  317. PostDataByName(this.requestParam).then(response => {
  318. console.log('新增保存发送参数', this.requestParam)
  319. if (response.msg !== 'fail') {
  320. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  321. this.getList()
  322. } else {
  323. const isRepeat = new RegExp('Duplicate entry')
  324. if (isRepeat.test(response.data)) {
  325. this.$message({ type: 'error', message: '角色名称不可重复', duration: 2000 })
  326. } else {
  327. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  328. }
  329. }
  330. })
  331. },
  332. createCancel(row) {
  333. console.log('点击了新增取消')
  334. for (let i = 0; i < this.table.list.length; i++) {
  335. if (row.myId === this.table.list[i].myId) {
  336. var listIndex = this.table.list.indexOf(this.table.list[i])
  337. }
  338. if (listIndex > -1) {
  339. this.table.list.splice(listIndex, 1)
  340. return
  341. }
  342. }
  343. },
  344. handleUpdate(row) {
  345. console.log('点击了编辑')
  346. for (let i = 0; i < this.table.list.length; i++) {
  347. if (this.table.list[i].Edit == true) {
  348. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  349. return false
  350. }
  351. }
  352. // 编辑true,不可编辑false
  353. row.Edit = true
  354. row.NoEdit = false
  355. // 新增false,编辑false,编辑保存true
  356. row.isCreate = false
  357. row.isUpdate = false
  358. row.isUpdateSave = true
  359. },
  360. updateData(row) {
  361. console.log('点击了编辑保存', row)
  362. this.table.temp.pastureid = Cookies.get('pastureid')
  363. this.table.temp.id = row.id
  364. this.table.temp.empname = row.empname
  365. this.table.temp.rolename = row.rolename
  366. this.table.temp.enable = row.enable
  367. this.table.temp.remark = row.remark
  368. // 检验角色名称/角色是否为空
  369. if (this.table.temp.rolename == '') {
  370. this.$message({ type: 'error', message: '角色名称不能为空', duration: 2000 })
  371. return false
  372. }
  373. this.isokDisable = true
  374. setTimeout(() => {
  375. this.isokDisable = false
  376. }, 1000)
  377. this.requestParam.name = 'updateRole'
  378. this.requestParam.parammaps = this.table.temp
  379. PostDataByName(this.requestParam).then(response => {
  380. console.log('新增保存发送参数', this.requestParam)
  381. if (response.msg !== 'fail') {
  382. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  383. this.getList()
  384. } else {
  385. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  386. }
  387. })
  388. },
  389. updateCancel(row) {
  390. console.log('点击了编辑取消')
  391. // 编辑false,不可编辑true
  392. row.Edit = false
  393. row.NoEdit = true
  394. // 新增false,编辑true,编辑保存false
  395. row.isCreate = false
  396. row.isUpdate = true
  397. row.isUpdateSave = false
  398. this.getList()
  399. },
  400. handleRowDelete(row) {
  401. console.log('点击了行内删除')
  402. MessageBox.confirm('是否确认删除此信息?', {
  403. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  404. }).then(() => {
  405. console.log(this.selectList)
  406. this.selectList = []
  407. this.requestParam = {}
  408. this.requestParam.common = { 'returnmap': '0' }
  409. this.requestParam.data = []
  410. this.requestParam.data[0] = { 'name': 'checkDeleteRole', 'type': 'v', 'parammaps': {
  411. 'pastureid': row.pastureid,
  412. 'id': row.id
  413. }}
  414. this.requestParam.data[1] = { 'name': 'deleteRole', 'type': 'e', 'parammaps': {
  415. 'pastureid': row.pastureid,
  416. 'id': row.id
  417. }}
  418. ExecDataByConfig(this.requestParam).then(response => {
  419. console.log('删除保存发送参数', this.requestParam)
  420. if (response.msg === 'fail') {
  421. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  422. } else {
  423. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  424. this.getList()
  425. }
  426. })
  427. }).catch(() => {
  428. this.$message({ type: 'info', message: '已取消删除' })
  429. })
  430. },
  431. handleSelectionChange(val) {
  432. console.log('勾选数据', val)
  433. this.selectList = val
  434. },
  435. handleDelete() {
  436. console.log('点击了删除')
  437. if (this.selectList.length == 0) {
  438. this.$message({ type: 'error', message: '请选择角色信息', duration: 2000 })
  439. } else {
  440. MessageBox.confirm('是否确认删除此信息?', {
  441. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  442. }).then(() => {
  443. console.log(this.selectList)
  444. this.requestParam.common = { 'returnmap': '0' }
  445. this.requestParam.data = []
  446. for (let i = 0; i < this.selectList.length; i++) {
  447. this.requestParam.data[i] = { 'name': 'checkDeleteRole', 'type': 'v', 'parammaps': {
  448. 'pastureid': this.selectList[i].pastureid,
  449. 'id': this.selectList[i].id
  450. }}
  451. }
  452. this.requestParam.data[this.selectList.length] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  453. this.requestParam.data[this.selectList.length].children = []
  454. this.requestParam.data[this.selectList.length].children[0] = { 'name': 'deleteRole', 'type': 'e', 'parammaps': {
  455. 'pastureid': '@insertSpotList.pastureid',
  456. 'id': '@insertSpotList.id'
  457. }}
  458. ExecDataByConfig(this.requestParam).then(response => {
  459. console.log('删除保存发送参数', this.requestParam)
  460. if (response.msg === 'fail') {
  461. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  462. } else {
  463. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  464. this.getList()
  465. }
  466. })
  467. })
  468. }
  469. },
  470. handleRole(row) {
  471. this.role.temp = Object.assign({}, row)
  472. console.log('点击了行内页面权限')
  473. this.dialogFull = false
  474. this.role.dialogStatus = 'role'
  475. this.role.dialogFormVisible = true
  476. this.tableData = []
  477. this.getRecuListParm.parammaps.roleid = row.id
  478. this.getRoleList()
  479. },
  480. getRoleList() {
  481. GetDataByName(this.getRecuListParm).then(response => {
  482. if (response.data.list !== null) {
  483. this.tableData = transData(response.data.list, 'id', 'pid', 'children')
  484. console.log(this.tableData)
  485. this.tableData.forEach((item, i) => {
  486. item.childList = item.children
  487. this.$set(item, 'fnCheck', {})
  488. this.$set(item, 'indeterminate', { 'seebutton': false, 'editbutton': false })
  489. if (item.seebutton == 1) { this.$set(item.fnCheck, 'seebutton', true) } else if (item.seebutton == 0) { this.$set(item.fnCheck, 'seebutton', false) } else if (item.seebutton == 2) { this.$set(item.indeterminate, 'seebutton', true) } else if (item.seebutton == 3) { this.$set(item.indeterminate, 'seebutton', false) }
  490. if (item.editbutton == 1) { this.$set(item.fnCheck, 'editbutton', true) } else if (item.editbutton == 0) { this.$set(item.fnCheck, 'editbutton', false) } else if (item.seebutton == 2) { this.$set(item.indeterminate, 'editbutton', true) } else if (item.seebutton == 3) { this.$set(item.indeterminate, 'editbutton', false) }
  491. if (item.seebutton == 2) { this.$set(item.indeterminate, 'seebutton', true) } else if (item.seebutton == 0) { this.$set(item.indeterminate, 'seebutton', false) }
  492. if (item.editbutton == 3) { this.$set(item.indeterminate, 'editbutton', true) } else if (item.editbutton == 0) { this.$set(item.indeterminate, 'editbutton', false) }
  493. if (item.childList !== undefined && item.childList.length > 0) {
  494. item.childList.forEach((item, i) => {
  495. this.$set(item, 'fnCheck', {})
  496. this.$set(item, 'indeterminate', { 'seebutton': false, 'editbutton': false })
  497. if (item.seebutton == 1) { this.$set(item.fnCheck, 'seebutton', true) } else if (item.seebutton == 0) { this.$set(item.fnCheck, 'seebutton', false) }
  498. if (item.editbutton == 1) { this.$set(item.fnCheck, 'editbutton', true) } else if (item.editbutton == 0) { this.$set(item.fnCheck, 'editbutton', false) }
  499. })
  500. }
  501. })
  502. console.log(this.tableData)
  503. }
  504. })
  505. },
  506. // 查找父级函数
  507. getParent(data2, nodeId2) {
  508. var arrRes = []
  509. if (data2.length === 0) {
  510. if (nodeId2) {
  511. arrRes.push(data2)
  512. }
  513. return arrRes
  514. }
  515. const rev = (data, nodeId) => {
  516. for (var i = 0, length = data.length; i < length; i++) {
  517. const node = data[i]
  518. if (node.id === nodeId) {
  519. arrRes.push(node)
  520. rev(data2, node.pid)
  521. break
  522. } else {
  523. if (node.childList) {
  524. rev(node.childList, nodeId)
  525. }
  526. }
  527. }
  528. return arrRes
  529. }
  530. arrRes = rev(data2, nodeId2)
  531. return arrRes
  532. },
  533. /**
  534. * 功能选择
  535. */
  536. // 子选框事件
  537. fnCheckEv(scope, type) {
  538. // 如果有子项,则子项的选框选择跟当前一致
  539. if (scope.row.childList) {
  540. console.log(scope.row)
  541. this.handleFnAll(scope.row, scope.row.fnCheck[type], scope.row.indeterminate[type], type)
  542. }
  543. // 查找父级选框
  544. this.getParent(this.tableData, scope.row.id).forEach((item, i) => {
  545. // console.log(item)
  546. if (type == 'seebutton') {
  547. if (!item.childList) {
  548. console.log(item)
  549. item.fnCheck[type] = scope.row.fnCheck[type]
  550. } else {
  551. let num = 0
  552. item.childList.forEach((item, i) => {
  553. if (item.fnCheck[type] === true) {
  554. num += 1
  555. }
  556. })
  557. if (num === item.childList.length) {
  558. console.log(item)
  559. item.fnCheck[type] = true
  560. item.indeterminate[type] = false
  561. } else {
  562. item.fnCheck[type] = false
  563. item.fnCheck['editbutton'] = false
  564. const childListArr = []
  565. const childEditListArr = []
  566. console.log(item.childList)
  567. item.childList.forEach((item, index) => {
  568. console.log(item) // d打印正常
  569. console.log(item.fnCheck) // d打印正常
  570. // console.log(item.fnCheck['editbutton'])//错误?
  571. console.log(item.fnCheck.editbutton)// 错误?
  572. childListArr.push(item.fnCheck[type])
  573. childEditListArr.push(item.fnCheck['editbutton'])
  574. })
  575. console.log(childEditListArr)
  576. if (childListArr.includes(true)) {
  577. item.indeterminate[type] = true
  578. item.fnCheck['editbutton'] = false
  579. console.log(childEditListArr)
  580. if (childEditListArr.includes(true)) { // 判断编辑子级是否有true
  581. item.indeterminate['editbutton'] = true
  582. } else {
  583. item.indeterminate['editbutton'] = false
  584. }
  585. if (item.childList.length > 0) {
  586. item.childList.forEach((item, i) => {
  587. if (item.fnCheck['editbutton'] === false) {
  588. item.fnCheck['editbutton'] = false
  589. } else {
  590. item.fnCheck['editbutton'] = item.fnCheck[type]
  591. }
  592. })
  593. }
  594. } else {
  595. item.indeterminate[type] = false
  596. console.log(item)
  597. // item.indeterminate['editbutton'] = false
  598. const editArr = []
  599. if (item.childList.length > 0) {
  600. item.childList.forEach((item, i) => {
  601. item.fnCheck['editbutton'] = item.fnCheck[type]
  602. editArr.push(item.fnCheck['editbutton'])
  603. })
  604. }
  605. if (editArr.includes(true)) { // 判断编辑子级是否有true
  606. item.indeterminate['editbutton'] = true
  607. } else {
  608. item.indeterminate['editbutton'] = false
  609. }
  610. }
  611. }
  612. }
  613. } else if (type == 'editbutton') {
  614. if (!item.childList) {
  615. item.fnCheck[type] = scope.row.fnCheck[type]
  616. } else {
  617. let num = 0
  618. item.childList.forEach((item, i) => {
  619. if (item.fnCheck[type] === true) {
  620. num += 1
  621. }
  622. })
  623. if (num === item.childList.length) {
  624. item.fnCheck[type] = true
  625. item.fnCheck['seebutton'] = true
  626. item.indeterminate[type] = false
  627. item.indeterminate['seebutton'] = false
  628. item.childList.forEach((item, i) => { // 编辑时,选中编辑的同时,选中查看
  629. console.log(item)
  630. if (item.fnCheck['seebutton'] === false) { // 查看未选中时,选中编辑可控制查看
  631. item.fnCheck['seebutton'] = item.fnCheck['editbutton']
  632. }
  633. })
  634. console.log(item)
  635. } else {
  636. console.log(item)
  637. item.fnCheck[type] = false
  638. console.log(item.fnCheck['seebutton'])
  639. if (item.fnCheck['seebutton'] === false) { // 查看未选中时,选中编辑可控制查看
  640. item.fnCheck['seebutton'] = false
  641. }
  642. const childListArr = []
  643. for (let i = 0; i < item.childList.length; i++) {
  644. childListArr.push(item.childList[i].fnCheck[type])
  645. }
  646. childListArr.includes(true)
  647. if (childListArr.includes(true)) {
  648. if (item.fnCheck['seebutton'] === false) {
  649. item.indeterminate['seebutton'] = true
  650. }
  651. item.indeterminate[type] = true
  652. } else {
  653. // if (item.fnCheck['seebutton'] === false) {
  654. // item.indeterminate['seebutton'] = false
  655. // }
  656. item.indeterminate[type] = false
  657. }
  658. // item.indeterminate[type] = true
  659. item.childList.forEach((item, i) => { // 编辑时,选中编辑的同时,选中查看
  660. if (item.fnCheck['seebutton'] === false) {
  661. item.fnCheck['seebutton'] = item.fnCheck['editbutton']
  662. }
  663. })
  664. console.log(item)
  665. }
  666. }
  667. }
  668. })
  669. },
  670. handleFnAll(row, fnCheck, indeterminate, type) {
  671. console.log(row, fnCheck, indeterminate, type)
  672. row.fnCheck[type] = fnCheck
  673. if (row.childList) {
  674. const that = this
  675. row.childList.forEach((element, i) => {
  676. row.indeterminate[type] = false
  677. console.log(fnCheck, indeterminate)
  678. // console.log(element, row.childList[i], fnCheck, indeterminate, type)
  679. that.handleFnAll(row.childList[i], fnCheck, indeterminate, type)
  680. })
  681. }
  682. },
  683. /**
  684. * 权限选择
  685. */
  686. // 权限:全部、自己
  687. // 子选框事件
  688. dataCheckEv(scope, type) {
  689. console.log(scope)
  690. const temp = scope.row.dataCheck[type]
  691. console.log(scope, type)
  692. for (const x in scope.row.dataCheck) {
  693. scope.row.dataCheck[x] = false
  694. }
  695. scope.row.dataCheck[type] = temp
  696. // 如果有子项,则子项的选框选择跟当前一致
  697. if (scope.row.childList) {
  698. this.handleDataAll(scope.row, scope.row.dataCheck[type], type)
  699. }
  700. // 查找父级选框
  701. this.getParent(this.tableData, scope.row.id).forEach((item, i) => {
  702. console.log(item, '==============674')
  703. for (const x in item.dataCheck) {
  704. item.dataCheck[x] = false
  705. }
  706. if (!item.childList) {
  707. console.log(item, '==============679')
  708. item.dataCheck[type] = temp
  709. } else {
  710. var num = 0
  711. item.childList.forEach((item, i) => {
  712. if (item.dataCheck[type] === true) {
  713. num += 1
  714. }
  715. })
  716. if (num === item.childList.length) {
  717. console.log(item, '==============689')
  718. item.dataCheck[type] = true
  719. } else {
  720. console.log(item, '==============691')
  721. item.dataCheck[type] = false
  722. }
  723. }
  724. })
  725. },
  726. handleDataAll(row, dataCheck, type) {
  727. for (const x in row.dataCheck) {
  728. row.dataCheck[x] = false
  729. }
  730. row.dataCheck[type] = dataCheck
  731. if (row.childList) {
  732. console.log(row, dataCheck, type)
  733. const that = this
  734. row.childList.forEach((element, i) => {
  735. that.handleDataAll(row.childList[i], dataCheck, type)
  736. })
  737. } else {
  738. console.log(row, dataCheck, type)
  739. }
  740. },
  741. renderSeeHeader(h, { column }) {
  742. return h(
  743. 'div',
  744. [
  745. h('span', column.label),
  746. h('el-checkbox', {
  747. style: 'display:inline-flex;margin-left:5px;',
  748. on: {
  749. change: ($event, column) => this.selectSee($event, column, 'see') // 选中事件 $event, column,这里$event=true,column是input的dom当在select里打印的时候
  750. }
  751. })
  752. ]
  753. )
  754. },
  755. renderEditHeader(h, { column }) {
  756. return h(
  757. 'div',
  758. [
  759. h('span', column.label),
  760. h('el-checkbox', {
  761. style: 'display:inline-flex;margin-left:5px;',
  762. on: {
  763. change: ($event, column) => this.selectEdit($event, column, 'edit') // 选中事件 $event, column,这里$event=true,column是input的dom当在select里打印的时候
  764. }
  765. })
  766. ]
  767. )
  768. },
  769. selectSee(obj, $event = this.targetEv, title) {
  770. const _this = this
  771. if ($event) {
  772. this.targetEv = $event // 这里是获取当前点击的input的dom元素赋值给this.targetEv,方便提交后初始化使用
  773. }
  774. if (obj === true) {
  775. this.flag = false
  776. } else {
  777. this.flag = true
  778. }
  779. this.targetEv.target.checked = obj
  780. this.targetEv.target.parentNode.className = obj ? 'el-checkbox__input is-checked' : 'el-checkbox__input'
  781. _this.tableData.forEach((item, index) => {
  782. _this.$set(_this.tableData[index], 'check', obj.toString())
  783. if (title === 'see') {
  784. if (obj === true) {
  785. item.fnCheck['seebutton'] = true
  786. if (item.childList.length > 0) {
  787. item.childList.forEach((item, index) => {
  788. item.fnCheck['seebutton'] = true
  789. })
  790. }
  791. } else {
  792. item.fnCheck['seebutton'] = false
  793. if (item.childList.length > 0) {
  794. item.childList.forEach((item, index) => {
  795. item.fnCheck['seebutton'] = false
  796. })
  797. }
  798. }
  799. }
  800. })
  801. },
  802. selectEdit(obj, $event = this.targetEv, title) {
  803. const _this = this
  804. if ($event) {
  805. this.targetEv = $event // 这里是获取当前点击的input的dom元素赋值给this.targetEv,方便提交后初始化使用
  806. }
  807. console.log('进来就错了', obj)
  808. if (obj === true) {
  809. this.flag = false
  810. } else {
  811. this.flag = true
  812. }
  813. this.targetEv.target.checked = obj
  814. this.targetEv.target.parentNode.className = obj ? 'el-checkbox__input is-checked' : 'el-checkbox__input'
  815. _this.tableData.forEach((item, index) => {
  816. _this.$set(_this.tableData[index], 'check', obj.toString())
  817. if (title === 'edit') {
  818. if (obj === true) {
  819. item.fnCheck['editbutton'] = true
  820. if (item.fnCheck['seebutton'] === false) {
  821. item.fnCheck['seebutton'] = true
  822. }
  823. if (item.childList.length > 0) {
  824. item.childList.forEach((item, index) => {
  825. item.fnCheck['editbutton'] = true
  826. if (item.fnCheck['seebutton'] === false) {
  827. item.fnCheck['seebutton'] = true
  828. }
  829. })
  830. }
  831. } else {
  832. item.fnCheck['editbutton'] = false
  833. if (item.childList.length > 0) {
  834. item.childList.forEach((item, index) => {
  835. item.fnCheck['editbutton'] = false
  836. })
  837. }
  838. }
  839. }
  840. })
  841. },
  842. roleData(row) {
  843. console.log('点击了权限确认', this.tableData)
  844. // console.log('点击了权限确认', JSON.stringify(this.tableData))
  845. const dataAll = []
  846. const dataArr = []
  847. const dataArr2 = []
  848. this.tableData.forEach((item, index) => {
  849. if (item.fnCheck.seebutton === true) { item.seebutton = 1 } else { item.seebutton = 0 }
  850. if (item.fnCheck.editbutton === true) { item.editbutton = 1 } else { item.editbutton = 0 }
  851. if (item.indeterminate.seebutton === true) { item.seebutton = 2 }
  852. if (item.indeterminate.editbutton === true) { item.editbutton = 3 }
  853. if (item.childList.length > 0) {
  854. item.childList.forEach((item, index) => {
  855. if (item.fnCheck.seebutton === true) { item.seebutton = 1 } else { item.seebutton = 0 }
  856. if (item.fnCheck.editbutton === true) { item.editbutton = 1 } else { item.editbutton = 0 }
  857. dataArr2.push({ 'menuid': item.menu_id, 'seebutton': item.seebutton, 'editbutton': item.editbutton })
  858. })
  859. }
  860. dataArr.push({ 'menuid': item.menu_id, 'seebutton': item.seebutton, 'editbutton': item.editbutton })
  861. })
  862. dataArr.forEach((item, index) => {
  863. dataAll.push({ 'menuid': item.menuid, 'seebutton': item.seebutton, 'editbutton': item.editbutton })
  864. })
  865. dataArr2.forEach((item, index) => {
  866. dataAll.push({ 'menuid': item.menuid, 'seebutton': item.seebutton, 'editbutton': item.editbutton })
  867. })
  868. this.requestParam.common = { 'returnmap': '0' }
  869. this.requestParam.data = []
  870. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': dataAll }}
  871. this.requestParam.data[0].children = []
  872. this.requestParam.data[0].children[0] = { 'name': 'insertRolemenu', 'type': 'e', 'parammaps': {
  873. pastureid: this.role.temp.pastureid,
  874. roleid: this.role.temp.id,
  875. menuid: '@insertSpotList.menuid',
  876. seebutton: '@insertSpotList.seebutton',
  877. editbutton: '@insertSpotList.editbutton'
  878. }}
  879. ExecDataByConfig(this.requestParam).then(response => {
  880. console.log('权限菜单保存发送参数', this.requestParam)
  881. if (response.msg === 'fail') {
  882. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  883. } else {
  884. this.$notify({ title: '', message: '保存成功', type: 'success', duration: 2000 })
  885. this.role.dialogFormVisible = false
  886. this.getList()
  887. }
  888. })
  889. }
  890. }
  891. }
  892. </script>
  893. <style lang="scss" scoped>
  894. .search{margin-top:10px;}
  895. .table{margin-top:10px;}
  896. .inside-base {
  897. position: relative;
  898. }
  899. .inside-base-main {
  900. width: 100%;
  901. background: #ffffff;
  902. box-shadow: 0px 0px 10px 0px rgba(231,232,238,1);
  903. border-radius: 4px;
  904. margin-bottom: 30px;
  905. }
  906. // 中间内容
  907. .inside-base-cont {
  908. margin: 0 20px;
  909. }
  910. .role-cont {
  911. position: relative;
  912. font-size: 16px;
  913. color: #333333;
  914. line-height: 40px;
  915. > span {
  916. width: 90px;
  917. height: 40px;
  918. text-align: right;
  919. float: left;
  920. margin-right: 10px;
  921. margin-bottom: 20px;
  922. }
  923. > div {
  924. position: relative;
  925. width: 100%;
  926. float: left;
  927. margin-bottom: 20px;
  928. >>> .el-input__inner {
  929. width: 320px;
  930. }
  931. }
  932. }
  933. .check-page-all {
  934. position: absolute;
  935. top: 13px;
  936. left: 11px;
  937. z-index: 99;
  938. }
  939. /* element-ui css */
  940. .inside-base {
  941. >>> .el-input__inner {
  942. font-size: 16px;
  943. color: #333333;
  944. }
  945. }
  946. </style>