主要更新uniapp相关功能
This commit is contained in:
1 parent
aa92ca40a2
commit
5b4dbb2b46
65 files changed
+8532
-1921
No files matched your search
@@ -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>
|
||||
Reference in new issue
Block a user