Newer
Older
KaiFengPC / src / views / document / fileManagement / readAuth / operate.vue
@zhangdeliang zhangdeliang on 23 May 4 KB 初始化项目
  1. <template>
  2. <div class="operate">
  3. <el-form
  4. ref="ruleForm"
  5. :model="form"
  6. class="dialogForm"
  7. :label-width="120"
  8. >
  9. <el-row :gutter="20">
  10. <el-col :span="24">
  11. <el-form-item label="文件名称:" prop="fileName">
  12. <el-input
  13. v-model="form.fileName"
  14. type="text"
  15. disabled
  16. />
  17. </el-form-item>
  18. </el-col>
  19. </el-row>
  20. <el-row :gutter="20">
  21. <el-col :span="24">
  22. <el-form-item label="分配部门权限:" prop="dept">
  23. <el-select
  24. v-model="form.dept"
  25. placeholder="请选择部门"
  26. style="width: 100%"
  27. multiple
  28. >
  29. <el-option
  30. v-for="item in options"
  31. :key="item.refId"
  32. :label="item.refName"
  33. :value="item.refId"
  34. />
  35. </el-select>
  36. </el-form-item>
  37. </el-col>
  38. </el-row>
  39. <el-row :gutter="20">
  40. <el-col :span="24">
  41. <el-form-item label="分配用户权限:" prop="user">
  42. <el-select
  43. v-model="form.user"
  44. placeholder="请选择用户"
  45. style="width: 100%"
  46. multiple
  47. >
  48. <el-option-group
  49. v-for="group in groupOptions"
  50. :key="group.label"
  51. :label="group.label"
  52. >
  53. <el-option
  54. v-for="item in group.options"
  55. :key="item.refId"
  56. :label="item.refName"
  57. :value="item.refId"
  58. />
  59. </el-option-group>
  60. </el-select>
  61. </el-form-item>
  62. </el-col>
  63. </el-row>
  64. </el-form>
  65. </div>
  66. </template>
  67.  
  68. <script setup>
  69. import { ref, reactive, onMounted, watch } from 'vue'
  70. import { inheritAttr } from '@/utils/v3'
  71. import { optTextMap } from '@/utils/map'
  72. import { required } from '@/utils/validate-helper'
  73. import { useDicts } from '@/hooks'
  74. import {
  75. getDocumentAuthorityDisAuthDepart,
  76. documentAuthorityEdit
  77. } from '@/api/document/fileManagement/readAuth'
  78.  
  79. const { proxy } = getCurrentInstance()
  80. const {
  81. document_save_type
  82. } = proxy.useDict('document_save_type')
  83.  
  84. const props = defineProps({
  85. curRow: {
  86. type: Object,
  87. default: () => ({})
  88. }
  89. })
  90. const { curRow } = props
  91. const emit = defineEmits(['close'])
  92. const form = reactive({
  93. fileId: curRow.id || '',
  94. fileName: curRow.fileName,
  95. dept: [],
  96. user: []
  97. })
  98. const rules = reactive({
  99. fileName: required('文件名称'),
  100. dept: required('部门'),
  101. user: required('用户')
  102. })
  103. const options = ref([])
  104. const groupOptions = ref([])
  105.  
  106. const submit = () => {
  107. proxy.$refs.ruleForm.validate(async (valid, fields) => {
  108. if (valid) {
  109. const refList = []
  110. if(form.dept?.length){
  111. refList.push({ refId: form.dept, refType: 'dept' })
  112. }
  113. if(form.user?.length){
  114. refList.push({ refId: form.user, refType: 'user' })
  115. }
  116. const params = {
  117. fileId: form.fileId,
  118. refList
  119. }
  120. const res = await documentAuthorityEdit(params)
  121. if(res?.code !== 200) return
  122. proxy.$modal.msgSuccess('操作成功')
  123. emit('close', { isRefresh: true })
  124. } else {
  125. console.log('error submit!', fields)
  126. }
  127. })
  128. }
  129.  
  130. const getDetail = async () => {
  131. const res = await getDocumentAuthorityDisAuthDepart({
  132. fileId: form.fileId
  133. })
  134. if(res?.code !== 200) return
  135. const deptList = res.data.deptList || []
  136. options.value = deptList
  137. const userList = res.data.userList || []
  138. const departmentNameList = Object.keys(userList)
  139. let checkedUserList = []
  140. for (const departmentName of departmentNameList) {
  141. if(!userList[departmentName]) continue
  142. const checkedUserItemList = userList[departmentName].filter(it => it.refFlag).map(it => it.refId)
  143. checkedUserList = checkedUserList.concat(checkedUserItemList)
  144. const departmentObj = {
  145. label: departmentName,
  146. options: userList[departmentName]
  147. }
  148. groupOptions.value.push(departmentObj)
  149. }
  150. form.dept = deptList.filter(it => it.refFlag).map(it => it.refId)
  151. form.user = checkedUserList
  152. }
  153.  
  154. onMounted(() => {
  155. if(form.fileId) getDetail()
  156. })
  157.  
  158. defineExpose({
  159. submit
  160. })
  161. </script>
  162.  
  163. <style lang="scss" scoped></style>