BasicInfo.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <script setup name="BasicInfo">
  2. import { storeToRefs } from 'pinia'
  3. import useFlowStore from '@/store/modules/flow'
  4. import { ref, nextTick, onMounted, computed, watch, onBeforeUnmount } from 'vue'
  5. import UseSelect from '@/components/scWorkflow/select'
  6. import flowDefinition from '@/api/flow/definition'
  7. import process from '@/api/flow/process'
  8. // 缓存 start
  9. import { EVENT_ENUM, EVENT_BUS, cacheTriggerFunc } from '@/utils/cacheHelper'
  10. const flowStore = useFlowStore()
  11. const { flowName, flowProcessId } = storeToRefs(flowStore)
  12. const cacheLoading = ref(false)
  13. const cacheLoadingNum = ref(600)
  14. const cacheLoadingFr = 1000
  15. const cacheLoadingIndex = ref(null)
  16. const cacheIndex = ref(null) // 缓存索引
  17. const cacheUpdateFr = 3000 // 缓存更新频率
  18. // 缓存 end
  19. const visiblePopover = ref(false)
  20. const selectVisible = ref(false)
  21. const useSelectRef = ref(null)
  22. const nodeRoleList = ref([])
  23. const nodeRoleManageList = ref([])
  24. const currentNode = ref('nodeRoleList')
  25. const processId = ref('') // 流程定义ID
  26. const formRef = ref()
  27. const options = ref([])
  28. const flowInfo = ref({
  29. processKey: '', // 流程唯一标识 key
  30. processName: '', // 流程定义名称
  31. displayName: '', // 流程显示名称
  32. processIcon: 'https://lf3-ea.bytetos.com/obj/goofy/ee/approval/approval-admin/image/iconLib/v5/cart.svg', // 流程图标
  33. categoryId: '', // 流程组分类ID
  34. useScope: 0, // 使用范围 0,全员 1,指定人员(业务关联) 2,均不可提交
  35. processActorList: [
  36. {
  37. actorId: 0, // 参与者ID
  38. actorName: '', // 参与者
  39. actorType: 0 // 参与者类型 0,用户 1,部门 2,用户组
  40. }
  41. ], // 流程参与者,当使用范围为指定人员时候设置
  42. processPermissionList: [
  43. {
  44. userId: 0, // 用户ID
  45. userName: '', // 用户名
  46. operateApproval: 0, // 允许编辑/停用/删除审批 0,否 1,
  47. operateOwner: 0, // 允许添加/移除审批负责人 0,否 1,是
  48. operateData: 0 // 允许审批数据查询与操作 0,否 1,是
  49. }
  50. ] // 流程定义权限
  51. })
  52. const rules = {
  53. processIcon: [
  54. {
  55. required: true,
  56. message: '请选择图标'
  57. }
  58. ],
  59. processKey: [
  60. {
  61. required: true,
  62. message: '请输入唯一标识'
  63. }
  64. ],
  65. processName: [
  66. {
  67. required: true,
  68. message: '请输入名称'
  69. }
  70. ],
  71. categoryId: [
  72. {
  73. required: true,
  74. message: '请选择分组'
  75. }
  76. ]
  77. }
  78. const validate = () => {
  79. return new Promise((resolve, reject) => {
  80. formRef.value.validate((valid, errObj) => {
  81. if (valid) {
  82. console.error('valid 成功')
  83. // cb?.(form.value)
  84. resolve(form.value)
  85. // return form.value
  86. return
  87. }
  88. return reject(['基本信息', errObj])
  89. })
  90. })
  91. }
  92. const openApprovePerson = () => {
  93. selectVisible.value = !selectVisible.value
  94. }
  95. const selectHandle = (type, data, name) => {
  96. currentNode.value = name
  97. openApprovePerson()
  98. nextTick(() => {
  99. useSelectRef.value.open(type, data)
  100. })
  101. }
  102. const selectContentEv = item => {
  103. if (currentNode.value === 'nodeRoleList') {
  104. nodeRoleList.value = item
  105. const flag = !item.length
  106. flowInfo.value.useScope = flag ? 0 : 1
  107. let processActorList = []
  108. for (let i in item) {
  109. processActorList.push({
  110. actorId: item[i].id,
  111. actorName: item[i].name,
  112. actorType: 0
  113. })
  114. }
  115. flowInfo.value.processActorList = processActorList
  116. } else {
  117. let processPermissionList = []
  118. for (let i in item) {
  119. processPermissionList.push({
  120. userId: item[i].id,
  121. userName: item[i].name,
  122. operateApproval: 0,
  123. operateOwner: 0,
  124. operateData: 0
  125. })
  126. }
  127. nodeRoleManageList.value = item
  128. flowInfo.value.processPermissionList = processPermissionList
  129. }
  130. }
  131. const delRole = (index, itemName) => {
  132. if (itemName === 'nodeRoleList') {
  133. nodeRoleList.value.splice(index, 1)
  134. } else {
  135. nodeRoleManageList.value.splice(index, 1)
  136. }
  137. }
  138. const getGroupList = async () => {
  139. const data = await flowDefinition.flowDefinitionListCategoryApi({})
  140. options.value = data || []
  141. }
  142. // 更新申请信息缓存
  143. const updateRemoteCache = async () => {
  144. try {
  145. const params = processId.value ? { ...flowInfo.value, processId: processId.value } : flowInfo.value
  146. const res = await process.progressCreateApi(params)
  147. flowProcessId.value = processId.value = res
  148. console.log('updateRemoteCache 实际调用接口, params = ', params, new Date().getTime())
  149. } catch (e) {
  150. console.log(e)
  151. }
  152. }
  153. const handleRemoteCacheRefresh = () => {
  154. cacheIndex.value && clearTimeout(cacheIndex.value)
  155. cacheIndex.value = setTimeout(() => {
  156. updateRemoteCache()
  157. }, cacheUpdateFr)
  158. }
  159. // 初始化缓存倒计时
  160. const handleCacheLoading = () => {
  161. cacheLoading.value = true
  162. cacheLoadingNum.value = 5
  163. cacheLoadingIndex.value && clearInterval(cacheLoadingIndex.value)
  164. cacheLoadingIndex.value = setInterval(() => {
  165. cacheLoadingNum.value = cacheLoadingNum.value - 1
  166. if (cacheLoadingNum.value <= 0) {
  167. cacheLoading.value = false
  168. cacheLoadingIndex.value && clearInterval(cacheLoadingIndex.value)
  169. bindCacheEvt()
  170. }
  171. }, cacheLoadingFr)
  172. }
  173. const closeCacheLoading = () => {
  174. console.log('组件销毁时: 关闭定时器---------')
  175. cacheLoadingIndex.value && clearInterval(cacheLoadingIndex.value)
  176. }
  177. const bindCacheEvt = () => {
  178. EVENT_BUS.off(EVENT_ENUM.UPDATE_CACHE)
  179. EVENT_BUS.on(EVENT_ENUM.UPDATE_CACHE, res => {
  180. console.log('dev.2 EVENT_ENUM.UPDATE_CACHE', res)
  181. handleRemoteCacheRefresh()
  182. })
  183. }
  184. // ----- 缓存相关 start ------
  185. const flowBaseInfoWatcher = computed(() => {
  186. const { processKey, processName, processIcon, categoryId, remark, useScope, processActorList, processPermissionList } = flowInfo.value
  187. // 只关注参数相关的数据变更
  188. const _s = {
  189. processKey, // 流程显示名称
  190. processName, // 流程定义名称
  191. processIcon, // 流程图标
  192. categoryId, // 流程组分类ID
  193. remark, // 备注说明
  194. useScope, // 使用范围 0,全员 1,指定人员(业务关联) 2,均不可提交
  195. processActorList, // 流程参与者,当使用范围为指定人员时候设置
  196. processPermissionList // 流程定义权限
  197. }
  198. console.log('第一步:监听的对象属性 ------', _s)
  199. return _s
  200. })
  201. watch(
  202. flowBaseInfoWatcher,
  203. (newVal, oldVal) => {
  204. console.log('第二步:执行同步emit方法 ------', newVal, oldVal)
  205. cacheTriggerFunc()
  206. },
  207. { deep: true }
  208. )
  209. // 流程名称变化
  210. watch(
  211. () => flowInfo.value.processName,
  212. newVal => {
  213. flowName.value = newVal
  214. }
  215. )
  216. // ----- 缓存相关 end ------
  217. onMounted(() => {
  218. getGroupList()
  219. handleCacheLoading()
  220. })
  221. onBeforeUnmount(() => {
  222. closeCacheLoading()
  223. })
  224. defineExpose({
  225. formRef,
  226. validate
  227. })
  228. </script>
  229. <template>
  230. <div class="base-info">
  231. <div v-if="cacheLoading" style="font-size: 18px; position: absolute; left: 10px; top: 20px; z-index: 9999; color: red">
  232. {{ cacheLoadingNum }}秒之后开启自动缓存...
  233. </div>
  234. <div class="base-info-panel">
  235. <el-form ref="formRef" :model="flowInfo" :rules="rules" label-position="top">
  236. <el-form-item label="图标" prop="processIcon">
  237. <el-space>
  238. <div class="icon-shower">
  239. <img :src="flowInfo.processIcon" alt="" />
  240. </div>
  241. </el-space>
  242. <el-popover placement="right-end" :width="450" trigger="focus" class="base-popover" :visible="visiblePopover">
  243. <div class="icon-selector__dialog__content">
  244. <div class="icon-selector-list">
  245. <div v-for="item in 27" :key="item" class="icon-selector-item" @click="visiblePopover = !visiblePopover">
  246. <img src="https://lf3-ea.bytetos.com/obj/goofy/ee/approval/approval-admin/image/iconLib/v5/cart.svg" alt="" />
  247. </div>
  248. </div>
  249. </div>
  250. <template #reference>
  251. <el-link :underline="false" @click="visiblePopover = !visiblePopover">修改</el-link>
  252. </template>
  253. </el-popover>
  254. </el-form-item>
  255. <el-form-item label="唯一标识 key" prop="processKey">
  256. <el-input v-model="flowInfo.processKey" clearable></el-input>
  257. </el-form-item>
  258. <el-form-item label="名称" prop="processName">
  259. <el-input v-model="flowInfo.processName" clearable></el-input>
  260. </el-form-item>
  261. <el-form-item label="说明" prop="remark">
  262. <el-input v-model="flowInfo.remark" type="textarea" clearable></el-input>
  263. </el-form-item>
  264. <el-form-item label="分组" prop="categoryId">
  265. <el-select v-model="flowInfo.categoryId">
  266. <el-option v-for="item in options" :key="item.categoryId" :label="item.categoryName" :value="item.categoryId" />
  267. </el-select>
  268. </el-form-item>
  269. <el-form-item label="谁可以发起该流程(不选择,默认全员)" prop="谁可以发起该流程">
  270. <div class="add-btn" @click="selectHandle(1, nodeRoleList, 'nodeRoleList')">
  271. <el-icon :size="18"><Plus /></el-icon>
  272. </div>
  273. <div class="tags-list" style="margin-top: 15px; width: 100%">
  274. <el-tag
  275. v-for="(role, index) in nodeRoleList"
  276. :key="role.id"
  277. type="info"
  278. closable
  279. style="margin-right: 8px"
  280. @close="delRole(index, 'nodeRoleList')"
  281. >{{ role.name }}</el-tag
  282. >
  283. </div>
  284. </el-form-item>
  285. <el-form-item label="管理员" prop="管理员">
  286. <div class="add-btn" @click="selectHandle(1, nodeRoleManageList, 'nodeRoleManageList')">
  287. <el-icon :size="18"><Plus /></el-icon>
  288. </div>
  289. <div class="tags-list" style="margin-top: 15px; width: 100%">
  290. <el-tag
  291. v-for="(role, index) in nodeRoleManageList"
  292. :key="role.id"
  293. type="info"
  294. closable
  295. style="margin-right: 8px"
  296. @close="delRole(index, 'nodeRoleManageList')"
  297. >{{ role.name }}</el-tag
  298. >
  299. </div>
  300. </el-form-item>
  301. </el-form>
  302. </div>
  303. <use-select v-if="selectVisible" ref="useSelectRef" @closed="selectVisible = false" @content-ev="selectContentEv"></use-select>
  304. </div>
  305. </template>
  306. <style scoped lang="scss">
  307. .basic-info-wrap {
  308. //background: var(--el-color-danger);
  309. }
  310. .flow-name {
  311. padding-right: 4px;
  312. color: var(--el-color-danger);
  313. }
  314. .base-info {
  315. margin: 0 auto;
  316. padding: 24px 0;
  317. height: 100%;
  318. text-align: center;
  319. overflow-y: auto;
  320. background-color: #eff0f1;
  321. position: relative;
  322. &-panel {
  323. display: inline-block;
  324. width: 1128px;
  325. padding: 24px 288px;
  326. background-color: #fff;
  327. text-align: left;
  328. }
  329. }
  330. .icon-selector__dialog__content {
  331. height: 384px;
  332. overflow-x: visible;
  333. overflow-y: scroll;
  334. scrollbar-width: none;
  335. -ms-overflow-style: none;
  336. .icon-selector-list {
  337. display: grid;
  338. grid-template-columns: repeat(5, 64px);
  339. grid-template-rows: repeat(auto, 64px);
  340. grid-gap: 16px;
  341. justify-content: flex-start;
  342. align-items: flex-start;
  343. flex-wrap: wrap;
  344. .icon-selector-item {
  345. width: 64px;
  346. height: 64px;
  347. padding: 8px;
  348. border: 1px solid #d0d3d6;
  349. box-sizing: border-box;
  350. border-radius: 6px;
  351. cursor: pointer;
  352. &:hover {
  353. border-color: #3370ff;
  354. }
  355. img {
  356. width: 100%;
  357. height: 100%;
  358. border-radius: 4px;
  359. overflow: hidden;
  360. }
  361. }
  362. }
  363. }
  364. .icon-shower {
  365. width: 48px;
  366. height: 48px;
  367. border-radius: 50%;
  368. overflow: hidden;
  369. img {
  370. width: 100%;
  371. height: 100%;
  372. object-fit: cover;
  373. }
  374. }
  375. .add-btn {
  376. width: 48px;
  377. height: 48px;
  378. font-family: PingFang SC, Microsoft YaHei;
  379. font-size: 14px;
  380. line-height: 20px;
  381. background-color: #eff0f1;
  382. border-radius: 50%;
  383. cursor: pointer;
  384. display: flex;
  385. justify-content: center;
  386. align-items: center;
  387. }
  388. </style>