myDocument.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. <template>
  2. <view class="my-document-container">
  3. <!-- 头部标题和操作 -->
  4. <view class="header">
  5. <text class="title">我发起的流程</text>
  6. <view class="header-actions">
  7. <u-icon name="list" size="24" color="#666" @click="toggleCategory"></u-icon>
  8. </view>
  9. </view>
  10. <!-- 搜索栏 -->
  11. <view v-if="showSearch" class="search-section">
  12. <view class="search-input">
  13. <u-input
  14. v-model="queryParams.flowCode"
  15. placeholder="请输入流程定义编码"
  16. border="bottom"
  17. clearable
  18. @confirm="handleQuery"
  19. ></u-input>
  20. </view>
  21. <view class="search-actions">
  22. <u-button type="primary" size="small" @click="handleQuery">搜索</u-button>
  23. <u-button size="small" @click="resetQuery">重置</u-button>
  24. </view>
  25. </view>
  26. <!-- 当前选中的分类显示 -->
  27. <view v-if="selectedCategory && selectedCategory.id" class="selected-category">
  28. <text class="category-label">当前分类:{{ getCategoryPath(selectedCategory) }}</text>
  29. <text class="category-clear" @click="clearCategory">清除</text>
  30. </view>
  31. <!-- 内容区域 -->
  32. <view class="content">
  33. <!-- 加载状态 -->
  34. <view v-if="loading" class="loading">
  35. <u-loading-icon></u-loading-icon>
  36. <text class="loading-text">加载中...</text>
  37. </view>
  38. <!-- 空数据 -->
  39. <view v-else-if="processInstanceList.length === 0" class="empty">
  40. <view class="empty-content">
  41. <u-icon name="file-text" size="80" color="#ddd"></u-icon>
  42. <text class="empty-text">暂无数据</text>
  43. </view>
  44. </view>
  45. <!-- 流程列表 -->
  46. <view v-else class="process-list">
  47. <view
  48. v-for="item in processInstanceList"
  49. :key="item.id"
  50. class="process-item"
  51. @click="handleView(item)"
  52. >
  53. <!-- 流程信息 -->
  54. <view class="process-header">
  55. <view class="process-title-row">
  56. <text class="process-name">{{ item.flowName }}</text>
  57. <u-tag
  58. :text="getStatusText(item.flowStatus)"
  59. :type="getStatusType(item.flowStatus)"
  60. plain
  61. size="mini"
  62. />
  63. </view>
  64. <text class="process-time">{{ formatTime(item.createTime) }}</text>
  65. </view>
  66. <!-- 操作按钮 - 方案三:简洁卡片式 -->
  67. <view class="process-actions-card" @click.stop>
  68. <view class="action-card-content">
  69. <view class="status-info">
  70. <!-- 状态信息可以在这里添加 -->
  71. </view>
  72. <view class="quick-actions">
  73. <view class="quick-btn" @click="handleView(item)">
  74. <u-icon name="eye" size="20" color="#666"></u-icon>
  75. <text class="btn-text">查看</text>
  76. </view>
  77. <view
  78. v-if="canEdit(item)"
  79. class="quick-btn"
  80. @click="handleEdit(item)"
  81. >
  82. <u-icon name="edit-pen" size="20" color="#666"></u-icon>
  83. <text class="btn-text">编辑</text>
  84. </view>
  85. <view
  86. v-if="item.flowStatus === 'waiting'"
  87. class="quick-btn"
  88. @click="handleCancel(item)"
  89. >
  90. <text
  91. class="iconfont icon-chexiao"
  92. style="
  93. font-size: 20px;
  94. color: #faad14;
  95. background-color: transparent;
  96. "
  97. ></text>
  98. <text class="btn-text" style="color: #faad14">撤销</text>
  99. </view>
  100. <view
  101. v-if="canDelete(item)"
  102. class="quick-btn"
  103. @click="handleDelete(item)"
  104. >
  105. <u-icon name="close" size="20" color="#ff4d4f"></u-icon>
  106. <text class="btn-text" style="color: #ff4d4f">删除</text>
  107. </view>
  108. </view>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. <!-- 分页加载 -->
  114. <view v-if="processInstanceList.length > 0 && !loading" class="pagination">
  115. <u-loadmore v-if="hasMore" status="loading" @loadmore="loadMore">
  116. <text>正在加载更多...</text>
  117. </u-loadmore>
  118. <view v-else class="load-end">
  119. <text>已加载全部数据</text>
  120. </view>
  121. </view>
  122. </view>
  123. <!-- 分类弹窗 -->
  124. <u-popup
  125. :show="showCategory"
  126. mode="right"
  127. width="500px"
  128. :safe-area-inset-bottom="false"
  129. :safe-area-inset-top="false"
  130. @close="showCategory = false"
  131. >
  132. <view class="category-popup">
  133. <!-- 弹窗头部 -->
  134. <view class="popup-header">
  135. <text class="popup-title">选择分类</text>
  136. <u-icon
  137. name="close"
  138. size="26"
  139. color="#666"
  140. @click="showCategory = false"
  141. ></u-icon>
  142. </view>
  143. <!-- 分类树 -->
  144. <scroll-view scroll-y class="category-tree">
  145. <view class="tree-content">
  146. <!-- 全部选项 -->
  147. <view
  148. class="tree-item"
  149. :class="{ active: !selectedCategory || !selectedCategory.id }"
  150. @click="selectCategory({ id: '', label: '全部' })"
  151. >
  152. <text class="tree-item-text">全部</text>
  153. </view>
  154. <!-- 如果没有数据,显示提示 -->
  155. <view
  156. v-if="categoryTree.length === 0"
  157. style="padding: 20px; text-align: center"
  158. >
  159. <text style="color: #999">暂无分类数据</text>
  160. </view>
  161. <!-- 渲染树形结构 -->
  162. <tree-node
  163. v-for="item in categoryTree"
  164. :key="item.id"
  165. :node="item"
  166. :selected-id="selectedCategory && selectedCategory.id"
  167. :default-expanded="true"
  168. @select="selectCategory"
  169. ></tree-node>
  170. </view>
  171. </scroll-view>
  172. </view>
  173. </u-popup>
  174. </view>
  175. </template>
  176. <script>
  177. import { workflowApi, getStatusStyle, formatTime, routerJump } from '@/common/workflow-api.js';
  178. import { getDict, getDictLabel } from '@/common/dict.js';
  179. import TreeNode from '@/components/TreeNode.vue';
  180. export default {
  181. components: {
  182. TreeNode,
  183. },
  184. data() {
  185. return {
  186. loading: false,
  187. showSearch: false,
  188. showCategory: false,
  189. processInstanceList: [],
  190. categoryOptions: [],
  191. categoryTree: [],
  192. selectedCategory: null,
  193. total: 0,
  194. hasMore: true,
  195. // 字典数据
  196. statusDict: [], // 工作流业务状态字典
  197. queryParams: {
  198. pageNum: 1,
  199. pageSize: 10,
  200. flowCode: '',
  201. category: '',
  202. },
  203. };
  204. },
  205. onLoad() {
  206. this.initData();
  207. },
  208. onReachBottom() {
  209. if (this.hasMore && !this.loading) {
  210. this.loadMore();
  211. }
  212. },
  213. onPullDownRefresh() {
  214. this.refreshData();
  215. },
  216. methods: {
  217. async initData() {
  218. await this.loadStatusDict();
  219. await this.loadCategoryTree();
  220. await this.getList();
  221. },
  222. async loadStatusDict() {
  223. try {
  224. console.log('🔍 开始加载工作流状态字典...');
  225. const statusData = await getDict('wf_business_status');
  226. this.statusDict = statusData || [];
  227. console.log('✅ 工作流状态字典加载完成:', this.statusDict);
  228. } catch (error) {
  229. console.error('❌ 加载工作流状态字典失败:', error);
  230. this.statusDict = [];
  231. }
  232. },
  233. async loadCategoryTree() {
  234. try {
  235. console.log('开始加载分类树...');
  236. const res = await workflowApi.categoryTree();
  237. console.log('API返回数据:', res);
  238. if (res.code === 200) {
  239. // 过滤掉"全部"选项,只保留真正的树形数据
  240. this.categoryOptions = res.data || [];
  241. this.categoryTree = (res.data || []).filter((item) => item.id !== '');
  242. console.log('原始数据:', this.categoryOptions);
  243. console.log('过滤后的树数据:', this.categoryTree);
  244. console.log('树数据长度:', this.categoryTree.length);
  245. } else {
  246. console.error('API返回错误:', res.msg);
  247. uni.showToast({
  248. title: res.msg || '加载分类失败',
  249. icon: 'error',
  250. });
  251. }
  252. } catch (e) {
  253. console.error('加载分类失败:', e);
  254. uni.showToast({
  255. title: '网络错误',
  256. icon: 'error',
  257. });
  258. }
  259. },
  260. async getList() {
  261. if (this.loading) return;
  262. this.loading = true;
  263. try {
  264. const res = await workflowApi.pageByCurrent(this.queryParams);
  265. if (res.code === 200) {
  266. if (this.queryParams.pageNum === 1) {
  267. this.processInstanceList = res.rows || [];
  268. } else {
  269. this.processInstanceList.push(...(res.rows || []));
  270. }
  271. this.total = res.total;
  272. this.hasMore = this.processInstanceList.length < this.total;
  273. } else {
  274. uni.showToast({ title: res.msg || '加载失败', icon: 'error' });
  275. }
  276. } catch (e) {
  277. console.error('加载数据失败:', e);
  278. uni.showToast({ title: '网络错误', icon: 'error' });
  279. } finally {
  280. this.loading = false;
  281. // 停止下拉刷新
  282. uni.stopPullDownRefresh();
  283. }
  284. },
  285. async loadMore() {
  286. if (!this.hasMore || this.loading) return;
  287. this.queryParams.pageNum++;
  288. await this.getList();
  289. },
  290. async refreshData() {
  291. this.queryParams.pageNum = 1;
  292. this.hasMore = true;
  293. await this.getList();
  294. },
  295. toggleSearch() {
  296. this.showSearch = !this.showSearch;
  297. },
  298. toggleCategory() {
  299. console.log('toggleCategory clicked, current showCategory:', this.showCategory);
  300. this.showCategory = !this.showCategory;
  301. console.log('toggleCategory after, showCategory:', this.showCategory);
  302. },
  303. selectCategory(category) {
  304. this.selectedCategory = category;
  305. this.queryParams.category = category.id;
  306. this.showCategory = false; // 关闭弹窗
  307. this.handleQuery();
  308. },
  309. clearCategory() {
  310. this.selectedCategory = null;
  311. this.queryParams.category = '';
  312. this.handleQuery();
  313. },
  314. getCategoryPath(category) {
  315. if (!category || !category.id) return '全部';
  316. // 查找分类路径
  317. const findPath = (nodes, targetId, path = []) => {
  318. for (const node of nodes) {
  319. const currentPath = [...path, node.label];
  320. if (node.id === targetId) {
  321. return currentPath;
  322. }
  323. if (node.children && node.children.length > 0) {
  324. const childPath = findPath(node.children, targetId, currentPath);
  325. if (childPath) return childPath;
  326. }
  327. }
  328. return null;
  329. };
  330. const path = findPath(this.categoryTree, category.id);
  331. return path ? path.join(' > ') : category.label;
  332. },
  333. handleQuery() {
  334. this.queryParams.pageNum = 1;
  335. this.hasMore = true;
  336. this.getList();
  337. },
  338. resetQuery() {
  339. this.queryParams = {
  340. pageNum: 1,
  341. pageSize: 10,
  342. flowCode: '',
  343. category: '',
  344. };
  345. this.selectedCategory = null;
  346. this.hasMore = true;
  347. this.getList();
  348. },
  349. handleEdit(item) {
  350. this.routerJump({
  351. businessId: item.businessId,
  352. taskId: item.id,
  353. type: 'update',
  354. formCustom: item.formCustom,
  355. formPath: item.formPath,
  356. });
  357. },
  358. handleView(item) {
  359. // 动态跳转到formPath对应的路径,携带businessId和flowStatus参数
  360. if (item.formPath) {
  361. // 确保路径以pages开头
  362. let fullPath = item.formPath;
  363. // 统一处理路径:去掉开头的/,然后添加pages前缀
  364. if (!fullPath.startsWith('pages/')) {
  365. // 如果以/开头,先去掉/
  366. if (fullPath.startsWith('/')) {
  367. fullPath = fullPath.substring(1);
  368. }
  369. // 添加pages前缀
  370. fullPath = `pages/${fullPath}`;
  371. }
  372. const url = `/${fullPath}?id=${item.businessId}&type=${item.flowStatus}`;
  373. // 添加调试信息
  374. console.log('原始formPath:', item.formPath);
  375. console.log('处理后的fullPath:', fullPath);
  376. console.log('最终跳转URL:', url);
  377. // 使用navigateTo进行跳转
  378. uni.navigateTo({
  379. url: url,
  380. fail: (err) => {
  381. console.error('页面跳转失败:', err);
  382. // 如果跳转失败,使用原有的routerJump方法作为备选
  383. this.routerJump({
  384. businessId: item.businessId,
  385. taskId: item.id,
  386. type: 'view',
  387. formCustom: item.formCustom,
  388. formPath: item.formPath,
  389. });
  390. },
  391. });
  392. } else {
  393. // 如果没有formPath,使用原有的routerJump方法作为备选
  394. this.routerJump({
  395. businessId: item.businessId,
  396. taskId: item.id,
  397. type: 'view',
  398. formCustom: item.formCustom,
  399. formPath: item.formPath,
  400. });
  401. }
  402. },
  403. async handleDelete(item) {
  404. try {
  405. const res = await uni.showModal({
  406. title: '确认删除',
  407. content: '是否确认删除该流程?',
  408. confirmText: '删除',
  409. confirmColor: '#f56c6c',
  410. });
  411. if (res.confirm) {
  412. this.loading = true;
  413. const deleteRes = await workflowApi.deleteByInstanceIds([item.id]);
  414. if (deleteRes.code === 200) {
  415. uni.showToast({ title: '删除成功', icon: 'success' });
  416. this.refreshData();
  417. } else {
  418. uni.showToast({ title: deleteRes.msg || '删除失败', icon: 'error' });
  419. }
  420. }
  421. } catch (e) {
  422. console.error('删除失败:', e);
  423. uni.showToast({ title: '删除失败', icon: 'error' });
  424. } finally {
  425. this.loading = false;
  426. }
  427. },
  428. async handleCancel(item) {
  429. try {
  430. const res = await uni.showModal({
  431. title: '确认撤销',
  432. content: '是否确认撤销该流程申请?',
  433. confirmText: '撤销',
  434. confirmColor: '#e6a23c',
  435. });
  436. if (res.confirm) {
  437. this.loading = true;
  438. const cancelData = {
  439. businessId: item.businessId,
  440. message: '申请人撤销流程!',
  441. };
  442. const cancelRes = await workflowApi.cancelProcessApply(cancelData);
  443. if (cancelRes.code === 200) {
  444. uni.showToast({ title: '撤销成功', icon: 'success' });
  445. this.refreshData();
  446. } else {
  447. uni.showToast({ title: cancelRes.msg || '撤销失败', icon: 'error' });
  448. }
  449. }
  450. } catch (e) {
  451. console.error('撤销失败:', e);
  452. uni.showToast({ title: '撤销失败', icon: 'error' });
  453. } finally {
  454. this.loading = false;
  455. }
  456. },
  457. getStatusText(status) {
  458. if (this.statusDict && this.statusDict.length > 0) {
  459. return getDictLabel(this.statusDict, status) || status || '未知';
  460. }
  461. // 字典未加载时的降级处理
  462. const statusMap = {
  463. draft: '草稿',
  464. waiting: '待审批',
  465. complete: '已完成',
  466. cancel: '已取消',
  467. back: '已退回',
  468. suspend: '挂起',
  469. terminate: '终止',
  470. };
  471. return statusMap[status] || '未知';
  472. },
  473. getStatusStyle(status) {
  474. return getStatusStyle(status);
  475. },
  476. getStatusType(status) {
  477. if (this.statusDict && this.statusDict.length > 0) {
  478. const dictItem = this.statusDict.find(
  479. (item) => String(item.value) === String(status),
  480. );
  481. if (dictItem && dictItem.elTagType) {
  482. return dictItem.elTagType;
  483. }
  484. }
  485. // 字典未加载或无样式信息时的降级处理
  486. const typeMap = {
  487. draft: 'info',
  488. waiting: 'warning',
  489. complete: 'success',
  490. cancel: 'info',
  491. back: 'error',
  492. suspend: 'warning',
  493. terminate: 'error',
  494. };
  495. return typeMap[status] || 'info';
  496. },
  497. formatTime(timeStr) {
  498. return formatTime(timeStr);
  499. },
  500. routerJump(params) {
  501. routerJump(params);
  502. },
  503. canEdit(item) {
  504. return item.flowStatus === 'draft' || item.flowStatus === 'back';
  505. },
  506. canDelete(item) {
  507. return (
  508. item.flowStatus === 'draft' ||
  509. item.flowStatus === 'cancel' ||
  510. item.flowStatus === 'back'
  511. );
  512. },
  513. },
  514. };
  515. </script>
  516. <style scoped>
  517. .my-document-container {
  518. background: #f5f5f5;
  519. min-height: 100vh;
  520. padding-bottom: 20px;
  521. }
  522. .header {
  523. display: flex;
  524. justify-content: space-between;
  525. align-items: center;
  526. padding: 10px 20px;
  527. background: #fff;
  528. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  529. }
  530. .title {
  531. font-size: 20px;
  532. font-weight: bold;
  533. color: #333;
  534. }
  535. .header-actions {
  536. display: flex;
  537. align-items: center;
  538. }
  539. .search-section {
  540. background: #fff;
  541. padding: 16px 20px;
  542. border-bottom: 1px solid #eee;
  543. }
  544. .search-input {
  545. margin-bottom: 12px;
  546. }
  547. .search-actions {
  548. display: flex;
  549. gap: 12px;
  550. }
  551. .selected-category {
  552. background: #fff;
  553. padding: 12px 20px;
  554. border-bottom: 1px solid #eee;
  555. display: flex;
  556. justify-content: space-between;
  557. align-items: center;
  558. }
  559. .category-label {
  560. font-size: 14px;
  561. color: #333;
  562. flex: 1;
  563. }
  564. .category-clear {
  565. font-size: 14px;
  566. color: #007aff;
  567. padding: 4px 8px;
  568. }
  569. .content {
  570. flex: 1;
  571. }
  572. .loading {
  573. display: flex;
  574. flex-direction: column;
  575. align-items: center;
  576. padding: 40px;
  577. }
  578. .loading-text {
  579. margin-top: 8px;
  580. color: #999;
  581. font-size: 14px;
  582. }
  583. .empty {
  584. padding: 40px 20px;
  585. }
  586. .empty-content {
  587. display: flex;
  588. flex-direction: column;
  589. align-items: center;
  590. justify-content: center;
  591. }
  592. .empty-text {
  593. font-size: 14px;
  594. color: #999;
  595. margin-top: 12px;
  596. }
  597. .process-list {
  598. padding: 16px 20px;
  599. }
  600. .process-item {
  601. background: #fff;
  602. border-radius: 12px;
  603. padding: 16px;
  604. margin-bottom: 12px;
  605. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  606. transition: box-shadow 0.2s;
  607. }
  608. .process-item:active {
  609. box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  610. }
  611. .process-header {
  612. margin-bottom: 12px;
  613. }
  614. .process-title-row {
  615. display: flex;
  616. justify-content: space-between;
  617. align-items: flex-start;
  618. margin-bottom: 8px;
  619. }
  620. .process-name {
  621. font-size: 16px;
  622. font-weight: 500;
  623. color: #333;
  624. flex: 1;
  625. margin-right: 12px;
  626. }
  627. .process-time {
  628. font-size: 12px;
  629. color: #999;
  630. }
  631. /* 简洁卡片式样式 */
  632. .process-actions-card {
  633. border-radius: 12px;
  634. }
  635. .action-card-content {
  636. display: flex;
  637. justify-content: space-between;
  638. align-items: center;
  639. }
  640. .status-info {
  641. display: flex;
  642. flex-direction: column;
  643. gap: 4px;
  644. }
  645. .quick-actions {
  646. display: flex;
  647. gap: 16px;
  648. align-items: center;
  649. }
  650. .quick-btn {
  651. display: flex;
  652. align-items: center;
  653. justify-content: center;
  654. transition: all 0.2s ease;
  655. padding: 8px;
  656. gap: 4px;
  657. }
  658. .btn-text {
  659. font-size: 12px;
  660. color: #666;
  661. margin-left: 2px;
  662. }
  663. .quick-btn:active {
  664. transform: scale(0.9);
  665. opacity: 0.7;
  666. }
  667. .pagination {
  668. padding: 16px 20px;
  669. }
  670. .load-end {
  671. text-align: center;
  672. padding: 16px;
  673. }
  674. .load-end text {
  675. font-size: 14px;
  676. color: #999;
  677. }
  678. /* 分类弹窗样式 */
  679. .category-popup {
  680. height: 100vh;
  681. display: flex;
  682. flex-direction: column;
  683. background: #fff;
  684. }
  685. .popup-header {
  686. padding: 16px 20px;
  687. border-bottom: 1px solid #eee;
  688. display: flex;
  689. justify-content: space-between;
  690. align-items: center;
  691. }
  692. .popup-title {
  693. font-size: 18px;
  694. font-weight: 500;
  695. color: #333;
  696. }
  697. .category-tree {
  698. flex: 1;
  699. height: 0;
  700. }
  701. .tree-content {
  702. padding: 8px 0;
  703. }
  704. .tree-item {
  705. padding: 12px 16px;
  706. border-bottom: 1px solid #f0f0f0;
  707. transition: background-color 0.2s;
  708. }
  709. .tree-item:active {
  710. background-color: #f5f5f5;
  711. }
  712. .tree-item.active {
  713. background-color: #e6f7ff;
  714. border-left: 3px solid #007aff;
  715. }
  716. .tree-item-text {
  717. font-size: 14px;
  718. color: #333;
  719. }
  720. </style>