416 lines
9.4 KiB
Vue
416 lines
9.4 KiB
Vue
<template>
|
||
<view class="page">
|
||
<view class="toolbar">
|
||
<view class="search-box" :class="{ 'is-focus': searchFocused }">
|
||
<view class="search-ico" aria-hidden="true" />
|
||
<input
|
||
class="search-input"
|
||
:value="searchKeyword"
|
||
confirm-type="search"
|
||
placeholder="搜索审批单"
|
||
placeholder-class="search-ph"
|
||
@input="onSearchInput"
|
||
@focus="searchFocused = true"
|
||
@blur="searchFocused = false"
|
||
/>
|
||
<view
|
||
v-if="searchKeyword"
|
||
class="search-clear"
|
||
@click="searchKeyword = ''"
|
||
>
|
||
<text class="search-clear__x">×</text>
|
||
</view>
|
||
</view>
|
||
|
||
<scroll-view scroll-x class="tabs" :show-scrollbar="false">
|
||
<view class="tabs-inner">
|
||
<view
|
||
class="tab"
|
||
:class="{ active: activeGroupId === '' }"
|
||
@click="activeGroupId = ''"
|
||
>
|
||
全部
|
||
</view>
|
||
<view
|
||
v-for="g in groupOptions"
|
||
:key="g.id"
|
||
class="tab"
|
||
:class="{ active: activeGroupId === g.id }"
|
||
@click="activeGroupId = g.id"
|
||
>
|
||
{{ g.groupName }}
|
||
</view>
|
||
</view>
|
||
</scroll-view>
|
||
</view>
|
||
|
||
<view v-if="loading" class="state state-loading">
|
||
<view class="pulse-dots" aria-hidden="true">
|
||
<view class="pulse-dot" />
|
||
<view class="pulse-dot" />
|
||
<view class="pulse-dot" />
|
||
</view>
|
||
<text class="state-loading__text">加载审批模板…</text>
|
||
</view>
|
||
<view v-else-if="!displayGroups.length" class="state">
|
||
暂无可发起的审批模板
|
||
</view>
|
||
<view v-else class="body">
|
||
<view v-for="sec in displayGroups" :key="sec.id" class="section">
|
||
<view class="section-hd">
|
||
<text class="section-name">{{ sec.name }}</text>
|
||
<text class="section-meta">{{ sec.apps.length }} 个表单</text>
|
||
</view>
|
||
<view class="card-row">
|
||
<view
|
||
v-for="row in sec.apps"
|
||
:key="row.id"
|
||
class="oa-app-card"
|
||
@click="onPick(row)"
|
||
>
|
||
<OaAppIcon :icon-url="row.iconUrl" size="xs" />
|
||
<text class="oa-app-card__name">{{ row.appName }}</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import OaAppIcon from '../../../components/OaAppIcon.vue'
|
||
import { fetchOaGroupList, fetchOaTemplates } from '../../../utils/oa-api.js'
|
||
import { forceRelogin, getToken } from '../../../utils/auth.js'
|
||
import { stashOaStartTitle } from '../../../utils/oa-h5.js'
|
||
|
||
export default {
|
||
components: { OaAppIcon },
|
||
data() {
|
||
return {
|
||
loading: false,
|
||
templates: [],
|
||
groupOptions: [],
|
||
searchKeyword: '',
|
||
searchFocused: false,
|
||
activeGroupId: ''
|
||
}
|
||
},
|
||
computed: {
|
||
displayGroups() {
|
||
const kw = (this.searchKeyword || '').trim().toLowerCase()
|
||
let list = [...(this.templates || [])]
|
||
if (this.activeGroupId) {
|
||
list = list.filter((a) => a.groupId === this.activeGroupId)
|
||
}
|
||
if (kw) {
|
||
list = list.filter((a) =>
|
||
String(a.appName || '')
|
||
.toLowerCase()
|
||
.includes(kw)
|
||
)
|
||
}
|
||
const bucket = new Map()
|
||
for (const g of this.groupOptions) {
|
||
bucket.set(g.id, { id: g.id, name: g.groupName, apps: [] })
|
||
}
|
||
const ungrouped = { id: '_ungrouped', name: '未分组', apps: [] }
|
||
for (const app of list) {
|
||
if (app.groupId && bucket.has(app.groupId)) {
|
||
bucket.get(app.groupId).apps.push(app)
|
||
} else {
|
||
ungrouped.apps.push(app)
|
||
}
|
||
}
|
||
if (this.activeGroupId) {
|
||
const one = bucket.get(this.activeGroupId)
|
||
return one && one.apps.length ? [one] : []
|
||
}
|
||
const sections = []
|
||
for (const g of this.groupOptions) {
|
||
const sec = bucket.get(g.id)
|
||
if (sec && sec.apps.length) sections.push(sec)
|
||
}
|
||
if (ungrouped.apps.length) sections.push(ungrouped)
|
||
return sections
|
||
}
|
||
},
|
||
onShow() {
|
||
if (!getToken()) {
|
||
forceRelogin('请先登录')
|
||
return
|
||
}
|
||
this.load()
|
||
},
|
||
methods: {
|
||
onSearchInput(e) {
|
||
const v =
|
||
e && e.detail && e.detail.value != null
|
||
? String(e.detail.value)
|
||
: e && e.target
|
||
? String(e.target.value || '')
|
||
: ''
|
||
this.searchKeyword = v
|
||
},
|
||
async load() {
|
||
this.loading = true
|
||
try {
|
||
const [groups, templates] = await Promise.all([
|
||
fetchOaGroupList(),
|
||
fetchOaTemplates()
|
||
])
|
||
this.groupOptions = (groups?.list || groups || []).map((g) => ({
|
||
id: g.id,
|
||
groupName: g.groupName || g.name || '分组'
|
||
}))
|
||
this.templates = templates?.list || templates || []
|
||
} catch (e) {
|
||
uni.showToast({ title: (e && e.message) || '加载失败', icon: 'none' })
|
||
this.templates = []
|
||
this.groupOptions = []
|
||
} finally {
|
||
this.loading = false
|
||
}
|
||
},
|
||
onPick(row) {
|
||
if (!row || !row.id) return
|
||
// 与「表单水槽」一致:navigateTo 只带 ASCII 参数。
|
||
// 流程名经 stash 传递,避免微信对含中文链接白屏(见上一步标题改动)。
|
||
stashOaStartTitle(row.appName)
|
||
uni.navigateTo({
|
||
url: '/pages/oa/start/webview?appId=' + encodeURIComponent(row.id)
|
||
})
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.page {
|
||
min-height: 100vh;
|
||
padding-bottom: 24rpx;
|
||
background: #f5f6f8;
|
||
}
|
||
.toolbar {
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 10;
|
||
background: #fff;
|
||
}
|
||
.search-box {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16rpx;
|
||
margin: 20rpx 24rpx 0;
|
||
height: 72rpx;
|
||
padding: 0 24rpx;
|
||
border-radius: 20rpx;
|
||
border: 1rpx solid #e8eaed;
|
||
background: #fafafa;
|
||
box-sizing: border-box;
|
||
transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
|
||
}
|
||
.search-box.is-focus {
|
||
border-color: #cbd5e1;
|
||
background: #fff;
|
||
box-shadow: 0 0 0 6rpx rgba(148, 163, 184, 0.18);
|
||
}
|
||
.search-ico {
|
||
position: relative;
|
||
width: 26rpx;
|
||
height: 26rpx;
|
||
border: 3rpx solid #94a3b8;
|
||
border-radius: 50%;
|
||
box-sizing: border-box;
|
||
flex-shrink: 0;
|
||
}
|
||
.search-ico::after {
|
||
content: '';
|
||
position: absolute;
|
||
width: 12rpx;
|
||
height: 3rpx;
|
||
right: -8rpx;
|
||
bottom: -5rpx;
|
||
background: #94a3b8;
|
||
border-radius: 3rpx;
|
||
transform: rotate(45deg);
|
||
}
|
||
.search-input {
|
||
flex: 1;
|
||
height: 72rpx;
|
||
font-size: 28rpx;
|
||
color: #1f2937;
|
||
min-width: 0;
|
||
}
|
||
.search-ph {
|
||
color: #b0b7c3;
|
||
}
|
||
.search-clear {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 40rpx;
|
||
height: 40rpx;
|
||
border-radius: 50%;
|
||
background: #e5e7eb;
|
||
flex-shrink: 0;
|
||
}
|
||
.search-clear__x {
|
||
font-size: 28rpx;
|
||
line-height: 1;
|
||
color: #6b7280;
|
||
margin-top: -2rpx;
|
||
}
|
||
.tabs {
|
||
width: 100%;
|
||
white-space: nowrap;
|
||
margin-top: 8rpx;
|
||
padding: 0 8rpx;
|
||
box-sizing: border-box;
|
||
border-bottom: 1rpx solid #f1f5f9;
|
||
}
|
||
.tabs-inner {
|
||
display: inline-flex;
|
||
align-items: stretch;
|
||
padding: 0 8rpx;
|
||
}
|
||
.tab {
|
||
position: relative;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
height: 80rpx;
|
||
padding: 0 28rpx;
|
||
font-size: 28rpx;
|
||
color: #64748b;
|
||
flex-shrink: 0;
|
||
}
|
||
.tab.active {
|
||
color: #166534;
|
||
font-weight: 600;
|
||
}
|
||
.tab.active::after {
|
||
content: '';
|
||
position: absolute;
|
||
left: 28rpx;
|
||
right: 28rpx;
|
||
bottom: 0;
|
||
height: 4rpx;
|
||
border-radius: 4rpx 4rpx 0 0;
|
||
background: #22c55e;
|
||
}
|
||
.state {
|
||
padding: 80rpx 24rpx;
|
||
text-align: center;
|
||
color: #999;
|
||
font-size: 28rpx;
|
||
}
|
||
/* 对齐 mobile-oa-h5 OaPulseLoading:品牌绿三点跳动 + muted 文案 */
|
||
.state-loading {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 28rpx;
|
||
min-height: 50vh;
|
||
padding: 96rpx 32rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
.pulse-dots {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16rpx;
|
||
}
|
||
.pulse-dot {
|
||
width: 16rpx;
|
||
height: 16rpx;
|
||
border-radius: 50%;
|
||
background: var(--brand-green, #22c55e);
|
||
animation: oa-pulse-bounce 1.2s ease-in-out infinite;
|
||
}
|
||
.pulse-dot:nth-child(2) {
|
||
animation-delay: 0.15s;
|
||
opacity: 0.75;
|
||
}
|
||
.pulse-dot:nth-child(3) {
|
||
animation-delay: 0.3s;
|
||
opacity: 0.55;
|
||
}
|
||
.state-loading__text {
|
||
font-size: 26rpx;
|
||
font-weight: 500;
|
||
color: var(--text-muted, #5f7a6d);
|
||
line-height: 1.4;
|
||
}
|
||
@keyframes oa-pulse-bounce {
|
||
0%,
|
||
80%,
|
||
100% {
|
||
transform: translateY(0);
|
||
}
|
||
40% {
|
||
transform: translateY(-12rpx);
|
||
}
|
||
}
|
||
.body {
|
||
padding: 24rpx 24rpx 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 24rpx;
|
||
}
|
||
.section {
|
||
background: #fff;
|
||
border: 1rpx solid #e5e7eb;
|
||
border-radius: 16rpx;
|
||
overflow: hidden;
|
||
padding: 8rpx 8rpx 12rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
.section-hd {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12rpx;
|
||
min-height: 64rpx;
|
||
padding: 0 16rpx;
|
||
margin-bottom: 4rpx;
|
||
}
|
||
.section-name {
|
||
font-size: 28rpx;
|
||
font-weight: 600;
|
||
color: #334155;
|
||
}
|
||
.section-meta {
|
||
margin-left: auto;
|
||
font-size: 22rpx;
|
||
color: #94a3b8;
|
||
}
|
||
.card-row {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
}
|
||
.oa-app-card {
|
||
width: 25%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
gap: 12rpx;
|
||
padding: 16rpx 8rpx 20rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
.oa-app-card:active {
|
||
opacity: 0.72;
|
||
}
|
||
.oa-app-card__name {
|
||
width: 100%;
|
||
font-size: 24rpx;
|
||
font-weight: 400;
|
||
color: #334155;
|
||
line-height: 1.35;
|
||
text-align: center;
|
||
word-break: break-all;
|
||
display: -webkit-box;
|
||
-webkit-box-orient: vertical;
|
||
-webkit-line-clamp: 2;
|
||
overflow: hidden;
|
||
}
|
||
</style>
|