add upload permission

This commit is contained in:
Timi
2026-01-29 11:58:18 +08:00
parent 81cb0b361d
commit 6e01e927b1
14 changed files with 213 additions and 36 deletions

View File

@@ -9,6 +9,7 @@ import { OrderType } from "../../../../types/Model";
import { PreviewImageMetadata } from "../../../../types/Attachment";
import { MediaItem, MediaItemType } from "../../../../types/UI";
import { JournalApi } from "../../../../api/JournalApi";
import Permission from "../../../../utils/Permission";
interface JournalData {
page: JournalPage;
@@ -23,6 +24,7 @@ interface JournalData {
isShowMoreMenu: boolean;
menuTop: number;
menuLeft: number;
canUpload: boolean;
}
Page({
@@ -52,7 +54,17 @@ Page({
stickyOffset: 0,
isShowMoreMenu: false,
menuTop: 0,
menuLeft: 0
menuLeft: 0,
canUpload: false
},
async onShow() {
const cached = Permission.getCachedUploadPermission();
if (cached !== null) {
this.setData({ canUpload: cached });
return;
}
const canUpload = await Permission.checkAndCacheUploadPermission();
this.setData({ canUpload });
},
onLoad() {
Events.reset("JOURNAL_REFRESH", () => {

View File

@@ -12,8 +12,8 @@
style="top: {{menuTop}}px; left: {{menuLeft}}px;"
catchtap="stopPropagation"
>
<t-cell title="新纪录" leftIcon="add" bind:tap="toCreater" />
<t-cell title="按列表查找" leftIcon="view-list" bind:tap="toSearch" />
<t-cell wx:if="{{canUpload}}" title="新纪录" leftIcon="add" bind:tap="toCreater" />
<t-cell wx:if="{{canUpload}}" title="按列表查找" leftIcon="view-list" bind:tap="toSearch" />
<t-cell title="按日期查找" leftIcon="calendar-1" bind:tap="toDate" />
<t-cell title="按地图查找" leftIcon="location" bind:tap="toMap" />
</t-cell-group>
@@ -53,4 +53,4 @@
</view>
</view>
<view wx:if="{{isFinished}}" class="start">已回到最初的起点</view>
</t-indexes>
</t-indexes>

View File

@@ -9,6 +9,7 @@ import { PreviewImageMetadata } from "../../../../types/Attachment";
import { MomentApi } from "../../../../api/MomentApi";
import { JournalApi } from "../../../../api/JournalApi";
import { Network } from "../../../../utils/Network";
import Permission from "../../../../utils/Permission";
type Item = {
id: number;
@@ -44,6 +45,7 @@ interface MomentData {
isVisibleArchivePopup: boolean;
archiveStep: ArchiveStep;
selectedJournalId: number | null;
canUpload: boolean;
}
Page({
@@ -64,10 +66,11 @@ Page({
isAuthLocation: false,
isVisibleArchivePopup: false,
archiveStep: "select-type",
selectedJournalId: null
selectedJournalId: null,
canUpload: false
},
async onLoad() {
this.fetch();
await this.fetch();
// 授权定位
const setting = await wx.getSetting();
@@ -116,6 +119,15 @@ Page({
});
});
},
async onShow() {
const cached = Permission.getCachedUploadPermission();
if (cached !== null) {
this.setData({ canUpload: cached });
} else {
const canUpload = await Permission.checkAndCacheUploadPermission();
this.setData({ canUpload });
}
},
async chooseLocation() {
const location = await wx.chooseLocation({});
this.setData({

View File

@@ -3,12 +3,12 @@
<t-navbar class="custom-navbar" title="瞬间" placeholder />
</view>
<view class="moment">
<view class="tips">
<view wx:if="{{canUpload}}" class="tips">
<text>由于微信限制,一次只能上传 20 张照片或视频,可以先在此页面分批次将所有照片或视频上传,</text>
<text style="color: #F30">记得勾选原图</text>
<text>。无需担心重复选择,已上传的文件不会再次上传。上传后有空再挑选归档,归档后此页面不再显示该照片或视频。</text>
</view>
<view class="action">
<view wx:if="{{canUpload}}" class="action">
<view class="line">
<t-button
class="btn upload"
@@ -49,7 +49,7 @@
>删除已选</t-button>
</view>
</view>
<view wx:if="{{isUploading}}" class="uploading">
<view wx:if="{{canUpload && isUploading}}" class="uploading">
<progress
class="progress"
percent="{{uploadProgress}}"
@@ -81,6 +81,7 @@
</view>
</view>
<t-popup
wx:if="{{canUpload}}"
class="archive-popup"
visible="{{isVisibleArchivePopup}}"
placement="bottom"
@@ -190,4 +191,4 @@
/>
</view>
</view>
</t-popup>
</t-popup>

View File

@@ -1,27 +1,54 @@
import Permission from "../../../../utils/Permission";
type NavItem = {
title: string;
icon: string;
url: string;
requiredUploadPermission: boolean;
};
interface OtherData {
navList: NavItem[];
canUpload: boolean;
}
const baseNavList: NavItem[] = [
{
title: "备忘录",
icon: "task-checked",
url: "/pages/main/other/memo/index",
requiredUploadPermission: true
},
{
title: "专拍",
icon: "face-retouching",
url: "/pages/main/other/portfolio/index",
requiredUploadPermission: false
}
];
function buildNavList(canUpload: boolean): NavItem[] {
if (canUpload) {
return [...baseNavList];
}
return baseNavList.filter((item) => !item.requiredUploadPermission);
}
Page({
data: <OtherData>{
navList: [
{
title: "备忘录",
icon: "task-checked",
url: "/pages/main/other/memo/index"
},
{
title: "专拍",
icon: "face-retouching",
url: "/pages/main/other/portfolio/index"
}
],
navList: buildNavList(false),
canUpload: false
},
async onShow() {
const cached = Permission.getCachedUploadPermission();
let canUpload = cached;
if (cached === null) {
canUpload = await Permission.checkAndCacheUploadPermission();
}
this.setData({
canUpload: !!canUpload,
navList: buildNavList(!!canUpload)
});
},
onNavTap(e: WechatMiniprogram.BaseEvent) {
const { url } = e.currentTarget.dataset as { url?: string };

View File

@@ -3,6 +3,7 @@
import Time from "../../../../utils/Time";
import { TravelApi } from "../../../../api/TravelApi";
import { Travel, TravelPage, TravelStatus, TravelStatusLabel, TravelStatusIcon, TransportationTypeLabel, TransportationTypeIcon } from "../../../../types/Travel";
import Permission from "../../../../utils/Permission";
interface TravelData {
/** 分页参数 */
@@ -28,6 +29,8 @@ interface TravelData {
transportLabels: typeof TransportationTypeLabel;
/** 交通类型图标映射 */
transportIcons: typeof TransportationTypeIcon;
/** 是否允许上传 */
canUpload: boolean;
}
Page({
@@ -46,12 +49,20 @@ Page({
statusLabels: TravelStatusLabel,
statusIcons: TravelStatusIcon,
transportLabels: TransportationTypeLabel,
transportIcons: TransportationTypeIcon
transportIcons: TransportationTypeIcon,
canUpload: false
},
onLoad() {
this.resetAndFetch();
},
onShow() {
async onShow() {
const cached = Permission.getCachedUploadPermission();
if (cached !== null) {
this.setData({ canUpload: cached });
} else {
const canUpload = await Permission.checkAndCacheUploadPermission();
this.setData({ canUpload });
}
// 页面显示时刷新数据(从编辑页返回时)
if (0 < this.data.list.length) {
this.resetAndFetch();

View File

@@ -96,6 +96,6 @@
<view wx:if="{{isFinished && 0 < list.length}}" class="finished">没有更多了</view>
</view>
<!-- 新建按钮 -->
<view class="fab" bind:tap="toCreate">
<view wx:if="{{canUpload}}" class="fab" bind:tap="toCreate">
<t-icon name="add" size="24px" color="#fff" />
</view>