| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817 |
- <template>
- <view class="my-document-container">
- <!-- 头部标题和操作 -->
- <view class="header">
- <text class="title">我发起的流程</text>
- <view class="header-actions">
- <u-icon name="list" size="24" color="#666" @click="toggleCategory"></u-icon>
- </view>
- </view>
- <!-- 搜索栏 -->
- <view v-if="showSearch" class="search-section">
- <view class="search-input">
- <u-input
- v-model="queryParams.flowCode"
- placeholder="请输入流程定义编码"
- border="bottom"
- clearable
- @confirm="handleQuery"
- ></u-input>
- </view>
- <view class="search-actions">
- <u-button type="primary" size="small" @click="handleQuery">搜索</u-button>
- <u-button size="small" @click="resetQuery">重置</u-button>
- </view>
- </view>
- <!-- 当前选中的分类显示 -->
- <view v-if="selectedCategory && selectedCategory.id" class="selected-category">
- <text class="category-label">当前分类:{{ getCategoryPath(selectedCategory) }}</text>
- <text class="category-clear" @click="clearCategory">清除</text>
- </view>
- <!-- 内容区域 -->
- <view class="content">
- <!-- 加载状态 -->
- <view v-if="loading" class="loading">
- <u-loading-icon></u-loading-icon>
- <text class="loading-text">加载中...</text>
- </view>
- <!-- 空数据 -->
- <view v-else-if="processInstanceList.length === 0" class="empty">
- <view class="empty-content">
- <u-icon name="file-text" size="80" color="#ddd"></u-icon>
- <text class="empty-text">暂无数据</text>
- </view>
- </view>
- <!-- 流程列表 -->
- <view v-else class="process-list">
- <view
- v-for="item in processInstanceList"
- :key="item.id"
- class="process-item"
- @click="handleView(item)"
- >
- <!-- 流程信息 -->
- <view class="process-header">
- <view class="process-title-row">
- <text class="process-name">{{ item.flowName }}</text>
- <u-tag
- :text="getStatusText(item.flowStatus)"
- :type="getStatusType(item.flowStatus)"
- plain
- size="mini"
- />
- </view>
- <text class="process-time">{{ formatTime(item.createTime) }}</text>
- </view>
- <!-- 操作按钮 - 方案三:简洁卡片式 -->
- <view class="process-actions-card" @click.stop>
- <view class="action-card-content">
- <view class="status-info">
- <!-- 状态信息可以在这里添加 -->
- </view>
- <view class="quick-actions">
- <view class="quick-btn" @click="handleView(item)">
- <u-icon name="eye" size="20" color="#666"></u-icon>
- <text class="btn-text">查看</text>
- </view>
- <view
- v-if="canEdit(item)"
- class="quick-btn"
- @click="handleEdit(item)"
- >
- <u-icon name="edit-pen" size="20" color="#666"></u-icon>
- <text class="btn-text">编辑</text>
- </view>
- <view
- v-if="item.flowStatus === 'waiting'"
- class="quick-btn"
- @click="handleCancel(item)"
- >
- <text
- class="iconfont icon-chexiao"
- style="
- font-size: 20px;
- color: #faad14;
- background-color: transparent;
- "
- ></text>
- <text class="btn-text" style="color: #faad14">撤销</text>
- </view>
- <view
- v-if="canDelete(item)"
- class="quick-btn"
- @click="handleDelete(item)"
- >
- <u-icon name="close" size="20" color="#ff4d4f"></u-icon>
- <text class="btn-text" style="color: #ff4d4f">删除</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 分页加载 -->
- <view v-if="processInstanceList.length > 0 && !loading" class="pagination">
- <u-loadmore v-if="hasMore" status="loading" @loadmore="loadMore">
- <text>正在加载更多...</text>
- </u-loadmore>
- <view v-else class="load-end">
- <text>已加载全部数据</text>
- </view>
- </view>
- </view>
- <!-- 分类弹窗 -->
- <u-popup
- :show="showCategory"
- mode="right"
- width="500px"
- :safe-area-inset-bottom="false"
- :safe-area-inset-top="false"
- @close="showCategory = false"
- >
- <view class="category-popup">
- <!-- 弹窗头部 -->
- <view class="popup-header">
- <text class="popup-title">选择分类</text>
- <u-icon
- name="close"
- size="26"
- color="#666"
- @click="showCategory = false"
- ></u-icon>
- </view>
- <!-- 分类树 -->
- <scroll-view scroll-y class="category-tree">
- <view class="tree-content">
- <!-- 全部选项 -->
- <view
- class="tree-item"
- :class="{ active: !selectedCategory || !selectedCategory.id }"
- @click="selectCategory({ id: '', label: '全部' })"
- >
- <text class="tree-item-text">全部</text>
- </view>
- <!-- 如果没有数据,显示提示 -->
- <view
- v-if="categoryTree.length === 0"
- style="padding: 20px; text-align: center"
- >
- <text style="color: #999">暂无分类数据</text>
- </view>
- <!-- 渲染树形结构 -->
- <tree-node
- v-for="item in categoryTree"
- :key="item.id"
- :node="item"
- :selected-id="selectedCategory && selectedCategory.id"
- :default-expanded="true"
- @select="selectCategory"
- ></tree-node>
- </view>
- </scroll-view>
- </view>
- </u-popup>
- </view>
- </template>
- <script>
- import { workflowApi, getStatusStyle, formatTime, routerJump } from '@/common/workflow-api.js';
- import { getDict, getDictLabel } from '@/common/dict.js';
- import TreeNode from '@/components/TreeNode.vue';
- export default {
- components: {
- TreeNode,
- },
- data() {
- return {
- loading: false,
- showSearch: false,
- showCategory: false,
- processInstanceList: [],
- categoryOptions: [],
- categoryTree: [],
- selectedCategory: null,
- total: 0,
- hasMore: true,
- // 字典数据
- statusDict: [], // 工作流业务状态字典
- queryParams: {
- pageNum: 1,
- pageSize: 10,
- flowCode: '',
- category: '',
- },
- };
- },
- onLoad() {
- this.initData();
- },
- onReachBottom() {
- if (this.hasMore && !this.loading) {
- this.loadMore();
- }
- },
- onPullDownRefresh() {
- this.refreshData();
- },
- methods: {
- async initData() {
- await this.loadStatusDict();
- await this.loadCategoryTree();
- await this.getList();
- },
- async loadStatusDict() {
- try {
- console.log('🔍 开始加载工作流状态字典...');
- const statusData = await getDict('wf_business_status');
- this.statusDict = statusData || [];
- console.log('✅ 工作流状态字典加载完成:', this.statusDict);
- } catch (error) {
- console.error('❌ 加载工作流状态字典失败:', error);
- this.statusDict = [];
- }
- },
- async loadCategoryTree() {
- try {
- console.log('开始加载分类树...');
- const res = await workflowApi.categoryTree();
- console.log('API返回数据:', res);
- if (res.code === 200) {
- // 过滤掉"全部"选项,只保留真正的树形数据
- this.categoryOptions = res.data || [];
- this.categoryTree = (res.data || []).filter((item) => item.id !== '');
- console.log('原始数据:', this.categoryOptions);
- console.log('过滤后的树数据:', this.categoryTree);
- console.log('树数据长度:', this.categoryTree.length);
- } else {
- console.error('API返回错误:', res.msg);
- uni.showToast({
- title: res.msg || '加载分类失败',
- icon: 'error',
- });
- }
- } catch (e) {
- console.error('加载分类失败:', e);
- uni.showToast({
- title: '网络错误',
- icon: 'error',
- });
- }
- },
- async getList() {
- if (this.loading) return;
- this.loading = true;
- try {
- const res = await workflowApi.pageByCurrent(this.queryParams);
- if (res.code === 200) {
- if (this.queryParams.pageNum === 1) {
- this.processInstanceList = res.rows || [];
- } else {
- this.processInstanceList.push(...(res.rows || []));
- }
- this.total = res.total;
- this.hasMore = this.processInstanceList.length < this.total;
- } else {
- uni.showToast({ title: res.msg || '加载失败', icon: 'error' });
- }
- } catch (e) {
- console.error('加载数据失败:', e);
- uni.showToast({ title: '网络错误', icon: 'error' });
- } finally {
- this.loading = false;
- // 停止下拉刷新
- uni.stopPullDownRefresh();
- }
- },
- async loadMore() {
- if (!this.hasMore || this.loading) return;
- this.queryParams.pageNum++;
- await this.getList();
- },
- async refreshData() {
- this.queryParams.pageNum = 1;
- this.hasMore = true;
- await this.getList();
- },
- toggleSearch() {
- this.showSearch = !this.showSearch;
- },
- toggleCategory() {
- console.log('toggleCategory clicked, current showCategory:', this.showCategory);
- this.showCategory = !this.showCategory;
- console.log('toggleCategory after, showCategory:', this.showCategory);
- },
- selectCategory(category) {
- this.selectedCategory = category;
- this.queryParams.category = category.id;
- this.showCategory = false; // 关闭弹窗
- this.handleQuery();
- },
- clearCategory() {
- this.selectedCategory = null;
- this.queryParams.category = '';
- this.handleQuery();
- },
- getCategoryPath(category) {
- if (!category || !category.id) return '全部';
- // 查找分类路径
- const findPath = (nodes, targetId, path = []) => {
- for (const node of nodes) {
- const currentPath = [...path, node.label];
- if (node.id === targetId) {
- return currentPath;
- }
- if (node.children && node.children.length > 0) {
- const childPath = findPath(node.children, targetId, currentPath);
- if (childPath) return childPath;
- }
- }
- return null;
- };
- const path = findPath(this.categoryTree, category.id);
- return path ? path.join(' > ') : category.label;
- },
- handleQuery() {
- this.queryParams.pageNum = 1;
- this.hasMore = true;
- this.getList();
- },
- resetQuery() {
- this.queryParams = {
- pageNum: 1,
- pageSize: 10,
- flowCode: '',
- category: '',
- };
- this.selectedCategory = null;
- this.hasMore = true;
- this.getList();
- },
- handleEdit(item) {
- this.routerJump({
- businessId: item.businessId,
- taskId: item.id,
- type: 'update',
- formCustom: item.formCustom,
- formPath: item.formPath,
- });
- },
- handleView(item) {
- // 动态跳转到formPath对应的路径,携带businessId和flowStatus参数
- if (item.formPath) {
- // 确保路径以pages开头
- let fullPath = item.formPath;
- // 统一处理路径:去掉开头的/,然后添加pages前缀
- if (!fullPath.startsWith('pages/')) {
- // 如果以/开头,先去掉/
- if (fullPath.startsWith('/')) {
- fullPath = fullPath.substring(1);
- }
- // 添加pages前缀
- fullPath = `pages/${fullPath}`;
- }
- const url = `/${fullPath}?id=${item.businessId}&type=${item.flowStatus}`;
- // 添加调试信息
- console.log('原始formPath:', item.formPath);
- console.log('处理后的fullPath:', fullPath);
- console.log('最终跳转URL:', url);
- // 使用navigateTo进行跳转
- uni.navigateTo({
- url: url,
- fail: (err) => {
- console.error('页面跳转失败:', err);
- // 如果跳转失败,使用原有的routerJump方法作为备选
- this.routerJump({
- businessId: item.businessId,
- taskId: item.id,
- type: 'view',
- formCustom: item.formCustom,
- formPath: item.formPath,
- });
- },
- });
- } else {
- // 如果没有formPath,使用原有的routerJump方法作为备选
- this.routerJump({
- businessId: item.businessId,
- taskId: item.id,
- type: 'view',
- formCustom: item.formCustom,
- formPath: item.formPath,
- });
- }
- },
- async handleDelete(item) {
- try {
- const res = await uni.showModal({
- title: '确认删除',
- content: '是否确认删除该流程?',
- confirmText: '删除',
- confirmColor: '#f56c6c',
- });
- if (res.confirm) {
- this.loading = true;
- const deleteRes = await workflowApi.deleteByInstanceIds([item.id]);
- if (deleteRes.code === 200) {
- uni.showToast({ title: '删除成功', icon: 'success' });
- this.refreshData();
- } else {
- uni.showToast({ title: deleteRes.msg || '删除失败', icon: 'error' });
- }
- }
- } catch (e) {
- console.error('删除失败:', e);
- uni.showToast({ title: '删除失败', icon: 'error' });
- } finally {
- this.loading = false;
- }
- },
- async handleCancel(item) {
- try {
- const res = await uni.showModal({
- title: '确认撤销',
- content: '是否确认撤销该流程申请?',
- confirmText: '撤销',
- confirmColor: '#e6a23c',
- });
- if (res.confirm) {
- this.loading = true;
- const cancelData = {
- businessId: item.businessId,
- message: '申请人撤销流程!',
- };
- const cancelRes = await workflowApi.cancelProcessApply(cancelData);
- if (cancelRes.code === 200) {
- uni.showToast({ title: '撤销成功', icon: 'success' });
- this.refreshData();
- } else {
- uni.showToast({ title: cancelRes.msg || '撤销失败', icon: 'error' });
- }
- }
- } catch (e) {
- console.error('撤销失败:', e);
- uni.showToast({ title: '撤销失败', icon: 'error' });
- } finally {
- this.loading = false;
- }
- },
- getStatusText(status) {
- if (this.statusDict && this.statusDict.length > 0) {
- return getDictLabel(this.statusDict, status) || status || '未知';
- }
- // 字典未加载时的降级处理
- const statusMap = {
- draft: '草稿',
- waiting: '待审批',
- complete: '已完成',
- cancel: '已取消',
- back: '已退回',
- suspend: '挂起',
- terminate: '终止',
- };
- return statusMap[status] || '未知';
- },
- getStatusStyle(status) {
- return getStatusStyle(status);
- },
- getStatusType(status) {
- if (this.statusDict && this.statusDict.length > 0) {
- const dictItem = this.statusDict.find(
- (item) => String(item.value) === String(status),
- );
- if (dictItem && dictItem.elTagType) {
- return dictItem.elTagType;
- }
- }
- // 字典未加载或无样式信息时的降级处理
- const typeMap = {
- draft: 'info',
- waiting: 'warning',
- complete: 'success',
- cancel: 'info',
- back: 'error',
- suspend: 'warning',
- terminate: 'error',
- };
- return typeMap[status] || 'info';
- },
- formatTime(timeStr) {
- return formatTime(timeStr);
- },
- routerJump(params) {
- routerJump(params);
- },
- canEdit(item) {
- return item.flowStatus === 'draft' || item.flowStatus === 'back';
- },
- canDelete(item) {
- return (
- item.flowStatus === 'draft' ||
- item.flowStatus === 'cancel' ||
- item.flowStatus === 'back'
- );
- },
- },
- };
- </script>
- <style scoped>
- .my-document-container {
- background: #f5f5f5;
- min-height: 100vh;
- padding-bottom: 20px;
- }
- .header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 10px 20px;
- background: #fff;
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
- }
- .title {
- font-size: 20px;
- font-weight: bold;
- color: #333;
- }
- .header-actions {
- display: flex;
- align-items: center;
- }
- .search-section {
- background: #fff;
- padding: 16px 20px;
- border-bottom: 1px solid #eee;
- }
- .search-input {
- margin-bottom: 12px;
- }
- .search-actions {
- display: flex;
- gap: 12px;
- }
- .selected-category {
- background: #fff;
- padding: 12px 20px;
- border-bottom: 1px solid #eee;
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .category-label {
- font-size: 14px;
- color: #333;
- flex: 1;
- }
- .category-clear {
- font-size: 14px;
- color: #007aff;
- padding: 4px 8px;
- }
- .content {
- flex: 1;
- }
- .loading {
- display: flex;
- flex-direction: column;
- align-items: center;
- padding: 40px;
- }
- .loading-text {
- margin-top: 8px;
- color: #999;
- font-size: 14px;
- }
- .empty {
- padding: 40px 20px;
- }
- .empty-content {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- }
- .empty-text {
- font-size: 14px;
- color: #999;
- margin-top: 12px;
- }
- .process-list {
- padding: 16px 20px;
- }
- .process-item {
- background: #fff;
- border-radius: 12px;
- padding: 16px;
- margin-bottom: 12px;
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
- transition: box-shadow 0.2s;
- }
- .process-item:active {
- box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
- }
- .process-header {
- margin-bottom: 12px;
- }
- .process-title-row {
- display: flex;
- justify-content: space-between;
- align-items: flex-start;
- margin-bottom: 8px;
- }
- .process-name {
- font-size: 16px;
- font-weight: 500;
- color: #333;
- flex: 1;
- margin-right: 12px;
- }
- .process-time {
- font-size: 12px;
- color: #999;
- }
- /* 简洁卡片式样式 */
- .process-actions-card {
- border-radius: 12px;
- }
- .action-card-content {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .status-info {
- display: flex;
- flex-direction: column;
- gap: 4px;
- }
- .quick-actions {
- display: flex;
- gap: 16px;
- align-items: center;
- }
- .quick-btn {
- display: flex;
- align-items: center;
- justify-content: center;
- transition: all 0.2s ease;
- padding: 8px;
- gap: 4px;
- }
- .btn-text {
- font-size: 12px;
- color: #666;
- margin-left: 2px;
- }
- .quick-btn:active {
- transform: scale(0.9);
- opacity: 0.7;
- }
- .pagination {
- padding: 16px 20px;
- }
- .load-end {
- text-align: center;
- padding: 16px;
- }
- .load-end text {
- font-size: 14px;
- color: #999;
- }
- /* 分类弹窗样式 */
- .category-popup {
- height: 100vh;
- display: flex;
- flex-direction: column;
- background: #fff;
- }
- .popup-header {
- padding: 16px 20px;
- border-bottom: 1px solid #eee;
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .popup-title {
- font-size: 18px;
- font-weight: 500;
- color: #333;
- }
- .category-tree {
- flex: 1;
- height: 0;
- }
- .tree-content {
- padding: 8px 0;
- }
- .tree-item {
- padding: 12px 16px;
- border-bottom: 1px solid #f0f0f0;
- transition: background-color 0.2s;
- }
- .tree-item:active {
- background-color: #f5f5f5;
- }
- .tree-item.active {
- background-color: #e6f7ff;
- border-left: 3px solid #007aff;
- }
- .tree-item-text {
- font-size: 14px;
- color: #333;
- }
- </style>
|