Files
yunzerwebsiteallinone/uniapp/pages/oa/document/index.vue
T

304 lines
6.2 KiB
Vue

<template>
<view class="page">
<view class="toolbar">
<u-tabs
:list="spaceTabs"
:current="spaceIndex"
:scrollable="false"
line-color="#2563eb"
:line-width="40"
:active-style="{ color: '#2563eb', fontWeight: '600' }"
:inactive-style="{ color: '#475569' }"
:item-style="{ height: '84rpx' }"
@change="onSpaceTabChange"
/>
<u-search
v-model="keyword"
placeholder="搜索文档名称、标签"
:show-action="false"
shape="round"
bg-color="#f1f5f9"
color="#0f172a"
custom-style="margin-top:12rpx;"
@search="loadDocs"
@clear="clearSearch"
/>
<scroll-view class="cat-scroll" scroll-x :show-scrollbar="false">
<view class="cat-row">
<view class="cat-chip" :class="{ active: categoryId === 0 && !uncategorized }" @tap="selectCategory(0)">
全部
</view>
<view class="cat-chip" :class="{ active: uncategorized }" @tap="selectUncategorized">未分类</view>
<view
v-for="cat in categories"
:key="cat.id"
class="cat-chip"
:class="{ active: categoryId === cat.id }"
@tap="selectCategory(cat.id)"
>{{ cat.name }}</view>
</view>
</scroll-view>
</view>
<scroll-view class="list-scroll" scroll-y :show-scrollbar="false">
<view v-if="loading" class="state-box">
<text class="state-text">加载中...</text>
</view>
<u-empty
v-else-if="list.length === 0"
mode="list"
:icon-size="80"
text="该分类下暂无文档"
/>
<view v-else class="doc-list">
<view v-for="item in list" :key="item.id" class="doc-card" @tap="openDetail(item.id)">
<view class="doc-icon">
<FaIcon :name="getDocTypeMeta(item.doc_type).icon" color="#ffffff" :size="20" />
</view>
<view class="doc-body">
<view class="doc-head">
<text class="doc-title">{{ item.title }}</text>
<FaIcon v-if="item.is_star === 1" name="star" color="#f7ba2a" :size="14" />
</view>
<view class="doc-meta">
<text>{{ getDocTypeMeta(item.doc_type).label }}</text>
<text v-if="item.ext">· {{ item.ext.toUpperCase() }}</text>
<text v-if="formatFileSize(item.size)">· {{ formatFileSize(item.size) }}</text>
<text v-if="item.is_online">· 在线文档</text>
</view>
<view class="doc-meta">
<text>{{ item.creator_name || item.owner_name || '未知' }}</text>
<text>· {{ item.update_time || item.create_time }}</text>
</view>
</view>
</view>
</view>
<view class="bottom-space" />
</scroll-view>
</view>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { fetchDocCategories, fetchDocs, getDocTypeMeta, formatFileSize } from '@/api/oa.js'
import { isLoggedIn } from '@/utils/auth.js'
const spaces = [
{ value: 'shared', label: '共享文档' },
{ value: 'personal', label: '私密文档' }
]
const spaceTabs = spaces.map((s) => ({ name: s.label }))
const scope = ref('shared')
const spaceIndex = computed(() => {
const i = spaces.findIndex((s) => s.value === scope.value)
return i < 0 ? 0 : i
})
const keyword = ref('')
const categoryId = ref(0)
const uncategorized = ref(false)
const categories = ref([])
const list = ref([])
const loading = ref(false)
onMounted(() => {
if (!isLoggedIn()) {
uni.reLaunch({ url: '/pages/login/login' })
return
}
loadCategories()
loadDocs()
})
async function loadCategories() {
try {
const tree = await fetchDocCategories(scope.value)
categories.value = Array.isArray(tree) ? tree : []
} catch (e) {
categories.value = []
}
}
async function loadDocs() {
loading.value = true
try {
const res = await fetchDocs({
scope: scope.value,
keyword: keyword.value,
categoryId: categoryId.value,
uncategorized: uncategorized.value,
pageSize: 50
})
list.value = res.list
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function changeScope(value) {
if (scope.value === value) return
scope.value = value
categoryId.value = 0
uncategorized.value = false
loadCategories()
loadDocs()
}
function onSpaceTabChange(item, index) {
const tab = spaces[index]
if (tab) changeScope(tab.value)
}
function selectCategory(id) {
categoryId.value = id
uncategorized.value = false
loadDocs()
}
function selectUncategorized() {
categoryId.value = 0
uncategorized.value = true
loadDocs()
}
function clearSearch() {
keyword.value = ''
loadDocs()
}
function openDetail(id) {
uni.navigateTo({ url: `/pages/oa/document/detail?id=${id}` })
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
display: flex;
flex-direction: column;
}
.toolbar {
flex-shrink: 0;
padding: 20rpx $page-padding-x 0;
background: $color-card;
box-shadow: $shadow-header;
}
.cat-scroll {
white-space: nowrap;
padding: 20rpx 0;
}
.cat-row {
display: inline-flex;
align-items: center;
gap: 14rpx;
}
.cat-chip {
flex-shrink: 0;
padding: 10rpx 26rpx;
font-size: 25rpx;
color: $color-text-secondary;
background: $color-bg-page;
border-radius: $radius-full;
&.active {
color: $color-primary;
background: $color-primary-bg;
font-weight: 500;
}
}
.list-scroll {
flex: 1;
height: 0;
}
.doc-list {
padding: 24rpx $page-padding-x 0;
}
.doc-card {
@include card;
display: flex;
align-items: center;
gap: 20rpx;
padding: 24rpx;
margin-bottom: 18rpx;
&:active {
background: $color-bg-page;
}
}
.doc-icon {
width: 80rpx;
height: 80rpx;
border-radius: $radius-md;
background: $color-primary;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.doc-body {
flex: 1;
min-width: 0;
}
.doc-head {
display: flex;
align-items: center;
gap: 10rpx;
}
.doc-title {
flex: 1;
min-width: 0;
font-size: 29rpx;
font-weight: 500;
color: $color-text;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.doc-meta {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 6rpx;
margin-top: 8rpx;
font-size: 22rpx;
color: $color-text-muted;
}
.state-box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 160rpx 48rpx;
gap: 20rpx;
}
.state-text {
font-size: 26rpx;
color: $color-text-muted;
text-align: center;
}
.bottom-space {
height: 40rpx;
}
</style>