主要更新uniapp相关功能

This commit is contained in:
hero920103 committed 2026-10-07 00:59:05 +08:00
1 parent aa92ca40a2
commit 5b4dbb2b46
65 files changed
+8532 -1921

No files matched your search

+346
View File
@@ -0,0 +1,346 @@
<template>
<view class="page">
<scroll-view class="body" scroll-y :show-scrollbar="false">
<view class="body-inner">
<view v-if="loading" class="state-box">
<text class="state-text">加载中...</text>
</view>
<u-empty
v-else-if="!doc"
mode="list"
:icon-size="80"
text="文档不存在或无访问权限"
/>
<block v-else>
<view class="head-card">
<view class="doc-icon">
<FaIcon :name="getDocTypeMeta(doc.doc_type).icon" color="#ffffff" :size="26" />
</view>
<view class="head-body">
<text class="title">{{ doc.title }}</text>
<view class="head-meta">
<text>{{ getDocTypeMeta(doc.doc_type).label }}</text>
<text v-if="doc.ext">· {{ doc.ext.toUpperCase() }}</text>
<text v-if="formatFileSize(doc.size)">· {{ formatFileSize(doc.size) }}</text>
<text v-if="doc.is_online">· 在线文档</text>
</view>
</view>
</view>
<view class="action-card">
<view class="action-btn-wrap">
<u-button
type="primary"
color="#2563eb"
icon="download"
text="下载"
:disabled="!doc.file_url"
@click="onDownload"
/>
</view>
<view class="action-btn-wrap">
<u-button
:type="doc.is_star === 1 ? 'warning' : 'info'"
:plain="doc.is_star !== 1"
:icon="doc.is_star === 1 ? 'star-fill' : 'star'"
:text="doc.is_star === 1 ? '已收藏' : '收藏'"
@click="onStar"
/>
</view>
</view>
<view class="info-card">
<view class="info-row">
<text class="info-label">所属分类</text>
<text class="info-value">{{ doc.visibility === 1 ? '私密文档' : '共享文档' }}</text>
</view>
<view class="info-row">
<text class="info-label">创建人</text>
<text class="info-value">{{ doc.creator_name || '-' }}</text>
</view>
<view class="info-row">
<text class="info-label">版本</text>
<text class="info-value">V{{ doc.version || 1 }}</text>
</view>
<view class="info-row">
<text class="info-label">创建时间</text>
<text class="info-value">{{ doc.create_time || '-' }}</text>
</view>
<view class="info-row">
<text class="info-label">更新时间</text>
<text class="info-value">{{ doc.update_time || '-' }}</text>
</view>
<view class="info-row">
<text class="info-label">浏览 / 下载</text>
<text class="info-value">{{ doc.view_count || 0 }} / {{ doc.download_count || 0 }}</text>
</view>
<view v-if="doc.tags" class="info-row">
<text class="info-label">标签</text>
<text class="info-value">{{ doc.tags }}</text>
</view>
</view>
<view v-if="doc.summary" class="summary-card">
<text class="section-title">文档摘要</text>
<text class="summary">{{ doc.summary }}</text>
</view>
</block>
<view class="bottom-space" />
</view>
</scroll-view>
</view>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { getDoc, downloadDoc, toggleDocStar, getDocTypeMeta, formatFileSize } from '@/api/oa.js'
import { isLoggedIn } from '@/utils/auth.js'
import { getBaseURL } from '@/api/request.js'
const id = ref(0)
const doc = ref(null)
const loading = ref(true)
onMounted(() => {
if (!isLoggedIn()) {
uni.reLaunch({ url: '/pages/login/login' })
return
}
const pages = getCurrentPages()
const current = pages[pages.length - 1]
id.value = Number((current && current.options && current.options.id) || 0)
loadDetail()
})
async function loadDetail() {
if (!id.value) {
loading.value = false
return
}
loading.value = true
try {
doc.value = await getDoc(id.value)
} catch (e) {
doc.value = null
} finally {
loading.value = false
}
}
/** 把可能的相对地址补全为绝对地址 */
function absoluteUrl(url) {
const value = String(url || '').trim()
if (!value) return ''
if (/^https?:/i.test(value)) return value
const base = String(getBaseURL() || '').replace(/\/$/, '')
if (value.startsWith('/')) return base + value
return base + '/' + value
}
async function onDownload() {
if (!doc.value) return
if (!doc.value.file_url) {
uni.showToast({ title: '该文档暂无可下载文件', icon: 'none' })
return
}
try {
const res = await downloadDoc(id.value)
if (doc.value) doc.value.download_count = (res && res.download_count) || doc.value.download_count
const url = absoluteUrl((res && res.file_url) || doc.value.file_url)
if (!url) {
uni.showToast({ title: '下载地址无效', icon: 'none' })
return
}
uni.showLoading({ title: '下载中...' })
uni.downloadFile({
url,
success(r) {
uni.hideLoading()
if (r.statusCode !== 200) {
copyLink(url)
return
}
uni.openDocument({
filePath: r.tempFilePath,
showMenu: true,
fail() {
copyLink(url)
}
})
},
fail() {
uni.hideLoading()
copyLink(url)
}
})
} catch (e) {
uni.showToast({ title: '下载失败', icon: 'none' })
}
}
function copyLink(url) {
uni.setClipboardData({
data: url,
success() {
uni.showToast({ title: '已复制下载链接,可在浏览器打开', icon: 'none' })
}
})
}
async function onStar() {
if (!doc.value) return
try {
const res = await toggleDocStar(id.value)
doc.value.is_star = res && res.is_star
uni.showToast({ title: doc.value.is_star === 1 ? '已收藏' : '已取消收藏', icon: 'none' })
} catch (e) {
uni.showToast({ title: '操作失败', icon: 'none' })
}
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
display: flex;
flex-direction: column;
}
.body {
flex: 1;
height: 0;
}
.body-inner {
padding: 24rpx $page-padding-x 0;
}
.head-card {
@include card;
display: flex;
align-items: center;
gap: 22rpx;
padding: 32rpx 28rpx;
}
.doc-icon {
width: 96rpx;
height: 96rpx;
border-radius: $radius-md;
background: $color-primary;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.head-body {
flex: 1;
min-width: 0;
}
.title {
display: block;
font-size: 32rpx;
font-weight: 600;
line-height: 1.45;
color: $color-text;
word-break: break-all;
}
.head-meta {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 6rpx;
margin-top: 12rpx;
font-size: 23rpx;
color: $color-text-muted;
}
.action-card {
display: flex;
gap: 20rpx;
margin-top: 20rpx;
}
.action-btn-wrap {
flex: 1;
}
.info-card {
@include card;
margin-top: 20rpx;
padding: 8rpx 28rpx;
}
.info-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24rpx;
padding: 22rpx 0;
& + & {
border-top: 1rpx solid $color-divider;
}
}
.info-label {
flex-shrink: 0;
font-size: 26rpx;
color: $color-text-muted;
}
.info-value {
flex: 1;
text-align: right;
font-size: 26rpx;
color: $color-text;
word-break: break-all;
}
.summary-card {
@include card;
margin-top: 20rpx;
padding: 28rpx;
}
.section-title {
display: block;
font-size: 28rpx;
font-weight: 600;
color: $color-text;
margin-bottom: 14rpx;
}
.summary {
font-size: 27rpx;
line-height: 1.7;
color: $color-text-secondary;
white-space: pre-wrap;
word-break: break-all;
}
.state-box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 200rpx 48rpx;
gap: 20rpx;
}
.state-text {
font-size: 26rpx;
color: $color-text-muted;
text-align: center;
}
.bottom-space {
height: 48rpx;
}
</style>
+304
View File
@@ -0,0 +1,304 @@
<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>