add upload permission
This commit is contained in:
@@ -86,4 +86,9 @@ export class JournalApi {
|
|||||||
static getListByIds(ids: number[]): Promise<Journal[]> {
|
static getListByIds(ids: number[]): Promise<Journal[]> {
|
||||||
return Network.post<Journal[]>("/journal/list/ids", ids);
|
return Network.post<Journal[]>("/journal/list/ids", ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 是否有上传权限 */
|
||||||
|
static canUpload(): Promise<boolean> {
|
||||||
|
return Network.post("/journal/can-upload");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,21 @@
|
|||||||
// app.ts
|
// app.ts
|
||||||
|
import Permission from "./utils/Permission";
|
||||||
|
|
||||||
|
const originPage = Page;
|
||||||
|
|
||||||
|
(globalThis as any).Page = function (options: WechatMiniprogram.Page.Options) {
|
||||||
|
const originalOnShow = options.onShow;
|
||||||
|
return originPage({
|
||||||
|
...options,
|
||||||
|
async onShow(...args: any[]) {
|
||||||
|
await Permission.checkAndCacheUploadPermission();
|
||||||
|
if (originalOnShow) {
|
||||||
|
return await originalOnShow.apply(this, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
App<IAppOption>({
|
App<IAppOption>({
|
||||||
globalData: {
|
globalData: {
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { OrderType } from "../../../../types/Model";
|
|||||||
import { PreviewImageMetadata } from "../../../../types/Attachment";
|
import { PreviewImageMetadata } from "../../../../types/Attachment";
|
||||||
import { MediaItem, MediaItemType } from "../../../../types/UI";
|
import { MediaItem, MediaItemType } from "../../../../types/UI";
|
||||||
import { JournalApi } from "../../../../api/JournalApi";
|
import { JournalApi } from "../../../../api/JournalApi";
|
||||||
|
import Permission from "../../../../utils/Permission";
|
||||||
|
|
||||||
interface JournalData {
|
interface JournalData {
|
||||||
page: JournalPage;
|
page: JournalPage;
|
||||||
@@ -23,6 +24,7 @@ interface JournalData {
|
|||||||
isShowMoreMenu: boolean;
|
isShowMoreMenu: boolean;
|
||||||
menuTop: number;
|
menuTop: number;
|
||||||
menuLeft: number;
|
menuLeft: number;
|
||||||
|
canUpload: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
@@ -52,7 +54,17 @@ Page({
|
|||||||
stickyOffset: 0,
|
stickyOffset: 0,
|
||||||
isShowMoreMenu: false,
|
isShowMoreMenu: false,
|
||||||
menuTop: 0,
|
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() {
|
onLoad() {
|
||||||
Events.reset("JOURNAL_REFRESH", () => {
|
Events.reset("JOURNAL_REFRESH", () => {
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
style="top: {{menuTop}}px; left: {{menuLeft}}px;"
|
style="top: {{menuTop}}px; left: {{menuLeft}}px;"
|
||||||
catchtap="stopPropagation"
|
catchtap="stopPropagation"
|
||||||
>
|
>
|
||||||
<t-cell title="新纪录" leftIcon="add" bind:tap="toCreater" />
|
<t-cell wx:if="{{canUpload}}" title="新纪录" leftIcon="add" bind:tap="toCreater" />
|
||||||
<t-cell title="按列表查找" leftIcon="view-list" bind:tap="toSearch" />
|
<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="calendar-1" bind:tap="toDate" />
|
||||||
<t-cell title="按地图查找" leftIcon="location" bind:tap="toMap" />
|
<t-cell title="按地图查找" leftIcon="location" bind:tap="toMap" />
|
||||||
</t-cell-group>
|
</t-cell-group>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { PreviewImageMetadata } from "../../../../types/Attachment";
|
|||||||
import { MomentApi } from "../../../../api/MomentApi";
|
import { MomentApi } from "../../../../api/MomentApi";
|
||||||
import { JournalApi } from "../../../../api/JournalApi";
|
import { JournalApi } from "../../../../api/JournalApi";
|
||||||
import { Network } from "../../../../utils/Network";
|
import { Network } from "../../../../utils/Network";
|
||||||
|
import Permission from "../../../../utils/Permission";
|
||||||
|
|
||||||
type Item = {
|
type Item = {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -44,6 +45,7 @@ interface MomentData {
|
|||||||
isVisibleArchivePopup: boolean;
|
isVisibleArchivePopup: boolean;
|
||||||
archiveStep: ArchiveStep;
|
archiveStep: ArchiveStep;
|
||||||
selectedJournalId: number | null;
|
selectedJournalId: number | null;
|
||||||
|
canUpload: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
@@ -64,10 +66,11 @@ Page({
|
|||||||
isAuthLocation: false,
|
isAuthLocation: false,
|
||||||
isVisibleArchivePopup: false,
|
isVisibleArchivePopup: false,
|
||||||
archiveStep: "select-type",
|
archiveStep: "select-type",
|
||||||
selectedJournalId: null
|
selectedJournalId: null,
|
||||||
|
canUpload: false
|
||||||
},
|
},
|
||||||
async onLoad() {
|
async onLoad() {
|
||||||
this.fetch();
|
await this.fetch();
|
||||||
|
|
||||||
// 授权定位
|
// 授权定位
|
||||||
const setting = await wx.getSetting();
|
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() {
|
async chooseLocation() {
|
||||||
const location = await wx.chooseLocation({});
|
const location = await wx.chooseLocation({});
|
||||||
this.setData({
|
this.setData({
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
<t-navbar class="custom-navbar" title="瞬间" placeholder />
|
<t-navbar class="custom-navbar" title="瞬间" placeholder />
|
||||||
</view>
|
</view>
|
||||||
<view class="moment">
|
<view class="moment">
|
||||||
<view class="tips">
|
<view wx:if="{{canUpload}}" class="tips">
|
||||||
<text>由于微信限制,一次只能上传 20 张照片或视频,可以先在此页面分批次将所有照片或视频上传,</text>
|
<text>由于微信限制,一次只能上传 20 张照片或视频,可以先在此页面分批次将所有照片或视频上传,</text>
|
||||||
<text style="color: #F30">记得勾选原图</text>
|
<text style="color: #F30">记得勾选原图</text>
|
||||||
<text>。无需担心重复选择,已上传的文件不会再次上传。上传后有空再挑选归档,归档后此页面不再显示该照片或视频。</text>
|
<text>。无需担心重复选择,已上传的文件不会再次上传。上传后有空再挑选归档,归档后此页面不再显示该照片或视频。</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="action">
|
<view wx:if="{{canUpload}}" class="action">
|
||||||
<view class="line">
|
<view class="line">
|
||||||
<t-button
|
<t-button
|
||||||
class="btn upload"
|
class="btn upload"
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
>删除已选</t-button>
|
>删除已选</t-button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view wx:if="{{isUploading}}" class="uploading">
|
<view wx:if="{{canUpload && isUploading}}" class="uploading">
|
||||||
<progress
|
<progress
|
||||||
class="progress"
|
class="progress"
|
||||||
percent="{{uploadProgress}}"
|
percent="{{uploadProgress}}"
|
||||||
@@ -81,6 +81,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<t-popup
|
<t-popup
|
||||||
|
wx:if="{{canUpload}}"
|
||||||
class="archive-popup"
|
class="archive-popup"
|
||||||
visible="{{isVisibleArchivePopup}}"
|
visible="{{isVisibleArchivePopup}}"
|
||||||
placement="bottom"
|
placement="bottom"
|
||||||
|
|||||||
@@ -1,27 +1,54 @@
|
|||||||
|
import Permission from "../../../../utils/Permission";
|
||||||
|
|
||||||
type NavItem = {
|
type NavItem = {
|
||||||
title: string;
|
title: string;
|
||||||
icon: string;
|
icon: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
requiredUploadPermission: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface OtherData {
|
interface OtherData {
|
||||||
navList: NavItem[];
|
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({
|
Page({
|
||||||
data: <OtherData>{
|
data: <OtherData>{
|
||||||
navList: [
|
navList: buildNavList(false),
|
||||||
{
|
canUpload: false
|
||||||
title: "备忘录",
|
},
|
||||||
icon: "task-checked",
|
async onShow() {
|
||||||
url: "/pages/main/other/memo/index"
|
const cached = Permission.getCachedUploadPermission();
|
||||||
},
|
let canUpload = cached;
|
||||||
{
|
if (cached === null) {
|
||||||
title: "专拍",
|
canUpload = await Permission.checkAndCacheUploadPermission();
|
||||||
icon: "face-retouching",
|
}
|
||||||
url: "/pages/main/other/portfolio/index"
|
this.setData({
|
||||||
}
|
canUpload: !!canUpload,
|
||||||
],
|
navList: buildNavList(!!canUpload)
|
||||||
|
});
|
||||||
},
|
},
|
||||||
onNavTap(e: WechatMiniprogram.BaseEvent) {
|
onNavTap(e: WechatMiniprogram.BaseEvent) {
|
||||||
const { url } = e.currentTarget.dataset as { url?: string };
|
const { url } = e.currentTarget.dataset as { url?: string };
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import Time from "../../../../utils/Time";
|
import Time from "../../../../utils/Time";
|
||||||
import { TravelApi } from "../../../../api/TravelApi";
|
import { TravelApi } from "../../../../api/TravelApi";
|
||||||
import { Travel, TravelPage, TravelStatus, TravelStatusLabel, TravelStatusIcon, TransportationTypeLabel, TransportationTypeIcon } from "../../../../types/Travel";
|
import { Travel, TravelPage, TravelStatus, TravelStatusLabel, TravelStatusIcon, TransportationTypeLabel, TransportationTypeIcon } from "../../../../types/Travel";
|
||||||
|
import Permission from "../../../../utils/Permission";
|
||||||
|
|
||||||
interface TravelData {
|
interface TravelData {
|
||||||
/** 分页参数 */
|
/** 分页参数 */
|
||||||
@@ -28,6 +29,8 @@ interface TravelData {
|
|||||||
transportLabels: typeof TransportationTypeLabel;
|
transportLabels: typeof TransportationTypeLabel;
|
||||||
/** 交通类型图标映射 */
|
/** 交通类型图标映射 */
|
||||||
transportIcons: typeof TransportationTypeIcon;
|
transportIcons: typeof TransportationTypeIcon;
|
||||||
|
/** 是否允许上传 */
|
||||||
|
canUpload: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
@@ -46,12 +49,20 @@ Page({
|
|||||||
statusLabels: TravelStatusLabel,
|
statusLabels: TravelStatusLabel,
|
||||||
statusIcons: TravelStatusIcon,
|
statusIcons: TravelStatusIcon,
|
||||||
transportLabels: TransportationTypeLabel,
|
transportLabels: TransportationTypeLabel,
|
||||||
transportIcons: TransportationTypeIcon
|
transportIcons: TransportationTypeIcon,
|
||||||
|
canUpload: false
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.resetAndFetch();
|
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) {
|
if (0 < this.data.list.length) {
|
||||||
this.resetAndFetch();
|
this.resetAndFetch();
|
||||||
|
|||||||
@@ -96,6 +96,6 @@
|
|||||||
<view wx:if="{{isFinished && 0 < list.length}}" class="finished">没有更多了</view>
|
<view wx:if="{{isFinished && 0 < list.length}}" class="finished">没有更多了</view>
|
||||||
</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" />
|
<t-icon name="add" size="24px" color="#fff" />
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { TravelApi } from "../../../../api/TravelApi";
|
|||||||
import { TravelLocationApi } from "../../../../api/TravelLocationApi";
|
import { TravelLocationApi } from "../../../../api/TravelLocationApi";
|
||||||
import config from "../../../../config/index";
|
import config from "../../../../config/index";
|
||||||
import { Travel, TravelStatusLabel, TravelStatusIcon, TransportationTypeLabel, TravelLocation, TravelLocationTypeLabel, TravelLocationTypeIcon, TransportationTypeIcon, TravelLocationType } from "../../../../types/Travel";
|
import { Travel, TravelStatusLabel, TravelStatusIcon, TransportationTypeLabel, TravelLocation, TravelLocationTypeLabel, TravelLocationTypeIcon, TransportationTypeIcon, TravelLocationType } from "../../../../types/Travel";
|
||||||
|
import Permission from "../../../../utils/Permission";
|
||||||
|
|
||||||
interface TravelLocationView extends TravelLocation {
|
interface TravelLocationView extends TravelLocation {
|
||||||
/** 预览图 */
|
/** 预览图 */
|
||||||
@@ -42,6 +43,8 @@ interface TravelDetailData {
|
|||||||
deleteDialogVisible: boolean;
|
deleteDialogVisible: boolean;
|
||||||
/** 删除确认文本 */
|
/** 删除确认文本 */
|
||||||
deleteConfirmText: string;
|
deleteConfirmText: string;
|
||||||
|
/** 是否允许上传 */
|
||||||
|
canUpload: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
@@ -60,7 +63,8 @@ Page({
|
|||||||
locationTypes: ["全部", ...Object.values(TravelLocationTypeLabel)],
|
locationTypes: ["全部", ...Object.values(TravelLocationTypeLabel)],
|
||||||
selectedLocationTypeIndex: 0,
|
selectedLocationTypeIndex: 0,
|
||||||
deleteDialogVisible: false,
|
deleteDialogVisible: false,
|
||||||
deleteConfirmText: ""
|
deleteConfirmText: "",
|
||||||
|
canUpload: false
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad(options: any) {
|
onLoad(options: any) {
|
||||||
@@ -79,10 +83,17 @@ Page({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow() {
|
async onShow() {
|
||||||
|
const cached = Permission.getCachedUploadPermission();
|
||||||
|
if (cached !== null) {
|
||||||
|
this.setData({ canUpload: cached });
|
||||||
|
} else {
|
||||||
|
const canUpload = await Permission.checkAndCacheUploadPermission();
|
||||||
|
this.setData({ canUpload });
|
||||||
|
}
|
||||||
// 页面显示时刷新地点列表(从编辑页返回时)
|
// 页面显示时刷新地点列表(从编辑页返回时)
|
||||||
if (this.data.travelId && !this.data.isLoading) {
|
if (this.data.travelId && !this.data.isLoading) {
|
||||||
this.fetchLocations(this.data.travelId);
|
await this.fetchLocations(this.data.travelId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<!--pages/main/travel/detail/index.wxml-->
|
<!--pages/main/travel/detail/index.wxml-->
|
||||||
<view class="custom-navbar">
|
<view class="custom-navbar">
|
||||||
<t-navbar title="出行详情" leftArrow placeholder bind:go-back="goBack">
|
<t-navbar title="出行详情" leftArrow placeholder bind:go-back="goBack">
|
||||||
<view slot="right" class="edit-btn" bind:tap="toEdit">
|
<view wx:if="{{canUpload}}" slot="right" class="edit-btn" bind:tap="toEdit">
|
||||||
<t-icon name="edit" size="24px" />
|
<t-icon name="edit" size="24px" />
|
||||||
</view>
|
</view>
|
||||||
</t-navbar>
|
</t-navbar>
|
||||||
@@ -61,7 +61,14 @@
|
|||||||
</view>
|
</view>
|
||||||
</picker>
|
</picker>
|
||||||
</view>
|
</view>
|
||||||
<t-icon slot="right-icon" name="add" size="20px" color="var(--theme-wx)" bind:tap="toAddLocation" />
|
<t-icon
|
||||||
|
wx:if="{{canUpload}}"
|
||||||
|
slot="right-icon"
|
||||||
|
name="add"
|
||||||
|
size="20px"
|
||||||
|
color="var(--theme-wx)"
|
||||||
|
bind:tap="toAddLocation"
|
||||||
|
/>
|
||||||
</t-cell>
|
</t-cell>
|
||||||
<t-cell wx:if="{{isLoadingLocations}}" class="loading">
|
<t-cell wx:if="{{isLoadingLocations}}" class="loading">
|
||||||
<t-loading slot="title" theme="dots" size="40rpx" />
|
<t-loading slot="title" theme="dots" size="40rpx" />
|
||||||
@@ -117,6 +124,7 @@
|
|||||||
<!-- 操作按钮 -->
|
<!-- 操作按钮 -->
|
||||||
<view class="section action">
|
<view class="section action">
|
||||||
<t-button
|
<t-button
|
||||||
|
wx:if="{{canUpload}}"
|
||||||
theme="danger"
|
theme="danger"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="large"
|
size="large"
|
||||||
@@ -127,6 +135,7 @@
|
|||||||
删除
|
删除
|
||||||
</t-button>
|
</t-button>
|
||||||
<t-button
|
<t-button
|
||||||
|
wx:if="{{canUpload}}"
|
||||||
theme="primary"
|
theme="primary"
|
||||||
size="large"
|
size="large"
|
||||||
icon="edit"
|
icon="edit"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { TravelLocation, TravelLocationTypeIcon, TravelLocationTypeLabel } from
|
|||||||
import { MediaAttachType, PreviewImageMetadata } from "../../../../types/Attachment";
|
import { MediaAttachType, PreviewImageMetadata } from "../../../../types/Attachment";
|
||||||
import { MapMarker, MediaItem, MediaItemType } from "../../../../types/UI";
|
import { MapMarker, MediaItem, MediaItemType } from "../../../../types/UI";
|
||||||
import Toolkit from "../../../../utils/Toolkit";
|
import Toolkit from "../../../../utils/Toolkit";
|
||||||
|
import Permission from "../../../../utils/Permission";
|
||||||
|
|
||||||
interface TravelLocationView extends TravelLocation {
|
interface TravelLocationView extends TravelLocation {
|
||||||
/** 媒体列表 */
|
/** 媒体列表 */
|
||||||
@@ -35,6 +36,8 @@ interface TravelLocationDetailData {
|
|||||||
deleteDialogVisible: boolean;
|
deleteDialogVisible: boolean;
|
||||||
/** 删除确认文本 */
|
/** 删除确认文本 */
|
||||||
deleteConfirmText: string;
|
deleteConfirmText: string;
|
||||||
|
/** 是否允许上传 */
|
||||||
|
canUpload: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
@@ -51,7 +54,8 @@ Page({
|
|||||||
},
|
},
|
||||||
mapMarkers: [],
|
mapMarkers: [],
|
||||||
deleteDialogVisible: false,
|
deleteDialogVisible: false,
|
||||||
deleteConfirmText: ""
|
deleteConfirmText: "",
|
||||||
|
canUpload: false
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad(options: any) {
|
onLoad(options: any) {
|
||||||
@@ -73,10 +77,17 @@ Page({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow() {
|
async onShow() {
|
||||||
|
const cached = Permission.getCachedUploadPermission();
|
||||||
|
if (cached !== null) {
|
||||||
|
this.setData({ canUpload: cached });
|
||||||
|
} else {
|
||||||
|
const canUpload = await Permission.checkAndCacheUploadPermission();
|
||||||
|
this.setData({ canUpload });
|
||||||
|
}
|
||||||
// 页面显示时刷新数据(从编辑页返回时)
|
// 页面显示时刷新数据(从编辑页返回时)
|
||||||
if (this.data.locationId && !this.data.isLoading && this.data.location) {
|
if (this.data.locationId && !this.data.isLoading && this.data.location) {
|
||||||
this.fetchDetail(this.data.locationId);
|
await this.fetchDetail(this.data.locationId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<!--pages/main/travel/location-detail/index.wxml-->
|
<!--pages/main/travel/location-detail/index.wxml-->
|
||||||
<view class="custom-navbar">
|
<view class="custom-navbar">
|
||||||
<t-navbar title="地点详情" leftArrow placeholder bind:go-back="goBack">
|
<t-navbar title="地点详情" leftArrow placeholder bind:go-back="goBack">
|
||||||
<view slot="right" class="edit-btn" bind:tap="toEdit">
|
<view wx:if="{{canUpload}}" slot="right" class="edit-btn" bind:tap="toEdit">
|
||||||
<t-icon name="edit" size="24px" />
|
<t-icon name="edit" size="24px" />
|
||||||
</view>
|
</view>
|
||||||
</t-navbar>
|
</t-navbar>
|
||||||
@@ -120,7 +120,7 @@
|
|||||||
</t-button>
|
</t-button>
|
||||||
</view>
|
</view>
|
||||||
<!-- 操作按钮 -->
|
<!-- 操作按钮 -->
|
||||||
<view class="section action">
|
<view wx:if="{{canUpload}}" class="section action">
|
||||||
<t-button
|
<t-button
|
||||||
theme="danger"
|
theme="danger"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
61
miniprogram/utils/Permission.ts
Normal file
61
miniprogram/utils/Permission.ts
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import { JournalApi } from "../api/JournalApi";
|
||||||
|
|
||||||
|
const UPLOAD_PERMISSION_KEY = "journal:can-upload";
|
||||||
|
let cachedCanUpload: boolean | null = null;
|
||||||
|
let pendingCheck: Promise<boolean> | null = null;
|
||||||
|
|
||||||
|
function parseCachedValue(value: unknown): boolean | null {
|
||||||
|
if (value === true || value === false) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
if (value === "true") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (value === "false") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Permission {
|
||||||
|
/** 获取缓存的上传权限(不存在则返回 null) */
|
||||||
|
static getCachedUploadPermission(): boolean | null {
|
||||||
|
if (cachedCanUpload !== null) {
|
||||||
|
return cachedCanUpload;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const value = wx.getStorageSync(UPLOAD_PERMISSION_KEY);
|
||||||
|
const parsed = parseCachedValue(value);
|
||||||
|
if (parsed !== null) {
|
||||||
|
cachedCanUpload = parsed;
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn("读取上传权限缓存失败", error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 检查并缓存上传权限 */
|
||||||
|
static async checkAndCacheUploadPermission(): Promise<boolean> {
|
||||||
|
if (pendingCheck) {
|
||||||
|
return await pendingCheck;
|
||||||
|
}
|
||||||
|
pendingCheck = (async () => {
|
||||||
|
try {
|
||||||
|
const canUpload = await JournalApi.canUpload();
|
||||||
|
cachedCanUpload = !!canUpload;
|
||||||
|
wx.setStorageSync(UPLOAD_PERMISSION_KEY, cachedCanUpload);
|
||||||
|
return cachedCanUpload;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("检查上传权限失败", error);
|
||||||
|
const cached = this.getCachedUploadPermission();
|
||||||
|
const fallback = cached !== null ? cached : false;
|
||||||
|
return fallback;
|
||||||
|
} finally {
|
||||||
|
pendingCheck = null;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return await pendingCheck;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user