Compare commits
8 Commits
81cb0b361d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92ee199f56 | ||
|
|
d9f41d8e4d | ||
|
|
b2cf9572a4 | ||
|
|
8269a29100 | ||
|
|
07a6bc2ef9 | ||
|
|
7d758d642a | ||
|
|
ca9eb0e33d | ||
|
|
6e01e927b1 |
@@ -86,4 +86,9 @@ export class JournalApi {
|
||||
static getListByIds(ids: number[]): Promise<Journal[]> {
|
||||
return Network.post<Journal[]>("/journal/list/ids", ids);
|
||||
}
|
||||
|
||||
/** 是否有上传权限 */
|
||||
static canUpload(): Promise<boolean> {
|
||||
return Network.post("/journal/can-upload");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,24 @@
|
||||
// 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>({
|
||||
globalData: {
|
||||
},
|
||||
onLaunch() {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"t-button": "tdesign-miniprogram/button/button",
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"t-dialog": "tdesign-miniprogram/dialog/dialog",
|
||||
"t-empty": "tdesign-miniprogram/empty/empty",
|
||||
"t-radio-group": "tdesign-miniprogram/radio-group/radio-group"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,3 +170,14 @@
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
}
|
||||
|
||||
page {
|
||||
.no-permission {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
background: var(--td-bg-color-page);
|
||||
min-height: 100vh;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { JournalType } from "../../../../types/Journal";
|
||||
import { MediaAttachType, PreviewImageMetadata } from "../../../../types/Attachment";
|
||||
import IOSize, { Unit } from "../../../../utils/IOSize";
|
||||
import { JournalApi } from "../../../../api/JournalApi";
|
||||
import Permission from "../../../../utils/Permission";
|
||||
|
||||
interface JournalEditorData {
|
||||
/** 模式:create 或 edit */
|
||||
@@ -48,6 +49,10 @@ interface JournalEditorData {
|
||||
deleteDialogVisible: boolean;
|
||||
/** 删除确认文本 */
|
||||
deleteConfirmText: string;
|
||||
/** 是否拥有上传权限 */
|
||||
canUpload: boolean;
|
||||
/** 是否已检查权限 */
|
||||
permissionChecked: boolean;
|
||||
}
|
||||
|
||||
Page({
|
||||
@@ -72,10 +77,16 @@ Page({
|
||||
},
|
||||
isAuthLocation: false,
|
||||
deleteDialogVisible: false,
|
||||
deleteConfirmText: ""
|
||||
deleteConfirmText: "",
|
||||
canUpload: false,
|
||||
permissionChecked: false
|
||||
},
|
||||
|
||||
async onLoad(options: any) {
|
||||
const canUpload = await this.ensureUploadPermission();
|
||||
if (!canUpload) {
|
||||
return;
|
||||
}
|
||||
// 授权定位
|
||||
const setting = await wx.getSetting();
|
||||
wx.setStorageSync("isAuthLocation", setting.authSetting["scope.userLocation"] || false);
|
||||
@@ -116,6 +127,35 @@ Page({
|
||||
this.getDefaultLocation();
|
||||
}
|
||||
},
|
||||
async ensureUploadPermission(): Promise<boolean> {
|
||||
const cached = Permission.getCachedUploadPermission();
|
||||
if (cached !== null) {
|
||||
this.setData({
|
||||
canUpload: cached,
|
||||
permissionChecked: true
|
||||
});
|
||||
if (!cached) {
|
||||
this.redirectNoPermission();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const canUpload = await Permission.checkAndCacheUploadPermission();
|
||||
this.setData({
|
||||
canUpload,
|
||||
permissionChecked: true
|
||||
});
|
||||
if (!canUpload) {
|
||||
this.redirectNoPermission();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
redirectNoPermission() {
|
||||
wx.switchTab({
|
||||
url: "/pages/main/tabs/journal/index"
|
||||
});
|
||||
},
|
||||
/** 获取默认定位(创建模式) */
|
||||
getDefaultLocation() {
|
||||
wx.getLocation({
|
||||
|
||||
@@ -1,108 +1,99 @@
|
||||
<!--pages/main/journal/editor/index.wxml-->
|
||||
<t-navbar title="{{mode === 'create' ? '新纪录' : '编辑记录'}}" placeholder>
|
||||
<text slot="left" bindtap="cancel">取消</text>
|
||||
</t-navbar>
|
||||
<scroll-view
|
||||
class="container"
|
||||
type="custom"
|
||||
scroll-y
|
||||
show-scrollbar="{{false}}"
|
||||
scroll-into-view="{{intoView}}"
|
||||
>
|
||||
<view class="content">
|
||||
<view wx:if="{{isLoading}}" class="loading">
|
||||
<text>加载中...</text>
|
||||
</view>
|
||||
<block wx:else>
|
||||
<view class="section">
|
||||
<textarea
|
||||
class="idea"
|
||||
placeholder="这一刻的想法..."
|
||||
model:value="{{idea}}"
|
||||
/>
|
||||
<block wx:if="{{canUpload}}">
|
||||
<t-navbar title="{{mode === 'create' ? '新纪录' : '编辑记录'}}" placeholder>
|
||||
<text slot="left" bindtap="cancel">取消</text>
|
||||
</t-navbar>
|
||||
<scroll-view
|
||||
class="container"
|
||||
type="custom"
|
||||
scroll-y
|
||||
show-scrollbar="{{false}}"
|
||||
scroll-into-view="{{intoView}}"
|
||||
>
|
||||
<view class="content">
|
||||
<view wx:if="{{isLoading}}" class="loading">
|
||||
<text>加载中...</text>
|
||||
</view>
|
||||
<view class="section type">
|
||||
<text class="label">类型:</text>
|
||||
<t-radio-group bind:change="onChangeType" default-value="{{type}}" borderless t-class="box">
|
||||
<t-radio class="radio" block="{{false}}" label="日常" value="NORMAL" />
|
||||
<t-radio class="radio" block="{{false}}" label="专拍" value="PORTFOLIO" />
|
||||
</t-radio-group>
|
||||
</view>
|
||||
<view class="section time">
|
||||
<text class="label">时间:</text>
|
||||
<picker class="picker" mode="date" model:value="{{date}}">
|
||||
<view class="picker">
|
||||
{{date}}
|
||||
</view>
|
||||
</picker>
|
||||
<picker class="picker" mode="time" model:value="{{time}}">
|
||||
<view class="picker">
|
||||
{{time}}
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="section location">
|
||||
<text class="label">位置:</text>
|
||||
<text wx:if="{{location}}" bind:tap="chooseLocation">{{location.text}}</text>
|
||||
<text wx:else bind:tap="chooseLocation">选择位置..</text>
|
||||
</view>
|
||||
<view class="section media">
|
||||
<view class="gallery">
|
||||
<!-- 创建模式:mediaList 显示新选择的媒体 -->
|
||||
<block wx:if="{{mode === 'create'}}">
|
||||
<block wx:for="{{mediaList}}" wx:key="index">
|
||||
<view class="item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.path}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
<block wx:else>
|
||||
<view class="section">
|
||||
<textarea
|
||||
class="idea"
|
||||
placeholder="这一刻的想法..."
|
||||
model:value="{{idea}}"
|
||||
/>
|
||||
</view>
|
||||
<view class="section type">
|
||||
<text class="label">类型:</text>
|
||||
<t-radio-group bind:change="onChangeType" default-value="{{type}}" borderless t-class="box">
|
||||
<t-radio class="radio" block="{{false}}" label="日常" value="NORMAL" />
|
||||
<t-radio class="radio" block="{{false}}" label="专拍" value="PORTFOLIO" />
|
||||
</t-radio-group>
|
||||
</view>
|
||||
<view class="section time">
|
||||
<text class="label">时间:</text>
|
||||
<picker class="picker" mode="date" model:value="{{date}}">
|
||||
<view class="picker">
|
||||
{{date}}
|
||||
</view>
|
||||
</picker>
|
||||
<picker class="picker" mode="time" model:value="{{time}}">
|
||||
<view class="picker">
|
||||
{{time}}
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="section location">
|
||||
<text class="label">位置:</text>
|
||||
<text wx:if="{{location}}" bind:tap="chooseLocation">{{location.text}}</text>
|
||||
<text wx:else bind:tap="chooseLocation">选择位置..</text>
|
||||
</view>
|
||||
<view class="section media">
|
||||
<view class="gallery">
|
||||
<!-- 创建模式:mediaList 显示新选择的媒体 -->
|
||||
<block wx:if="{{mode === 'create'}}">
|
||||
<block wx:for="{{mediaList}}" wx:key="index">
|
||||
<view class="item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
src="{{item.thumbPath}}"
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.path}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
<image
|
||||
src="{{item.thumbPath}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
</view>
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
/>
|
||||
</view>
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
/>
|
||||
</view>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
<!-- 编辑模式:mediaList 显示现有附件,newMediaList 显示新添加的附件 -->
|
||||
<block wx:else>
|
||||
<!-- 现有附件 -->
|
||||
<block wx:for="{{mediaList}}" wx:key="attachmentId">
|
||||
<view class="item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.thumbURL}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
></image>
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
<!-- 编辑模式:mediaList 显示现有附件,newMediaList 显示新添加的附件 -->
|
||||
<block wx:else>
|
||||
<!-- 现有附件 -->
|
||||
<block wx:for="{{mediaList}}" wx:key="attachmentId">
|
||||
<view class="item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.thumbURL}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
@@ -110,134 +101,150 @@
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
<image
|
||||
src="{{item.thumbURL}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
</view>
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
/>
|
||||
</view>
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
/>
|
||||
</view>
|
||||
</block>
|
||||
<!-- 新选择附件 -->
|
||||
<block wx:for="{{newMediaList}}" wx:key="index">
|
||||
<view class="item new-item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.path}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
</block>
|
||||
<!-- 新选择附件 -->
|
||||
<block wx:for="{{newMediaList}}" wx:key="index">
|
||||
<view class="item new-item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
src="{{item.thumbPath}}"
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.path}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
<image
|
||||
src="{{item.thumbPath}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
</view>
|
||||
<!-- 新增标识 -->
|
||||
<t-icon class="new-badge" name="add" />
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
/>
|
||||
</view>
|
||||
<!-- 新增标识 -->
|
||||
<t-icon class="new-badge" name="add" />
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
/>
|
||||
</view>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
|
||||
<!-- 添加按钮 -->
|
||||
<t-button
|
||||
class="item add"
|
||||
theme="primary"
|
||||
plain="true"
|
||||
disabled="{{isSaving}}"
|
||||
bind:tap="addMedia"
|
||||
>
|
||||
<t-icon name="add" />
|
||||
</t-button>
|
||||
<!-- 添加按钮 -->
|
||||
<t-button
|
||||
class="item add"
|
||||
theme="primary"
|
||||
plain="true"
|
||||
disabled="{{isSaving}}"
|
||||
bind:tap="addMedia"
|
||||
>
|
||||
<t-icon name="add" />
|
||||
</t-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{isSaving}}" class="uploading">
|
||||
<progress
|
||||
class="progress"
|
||||
percent="{{uploadProgress}}"
|
||||
stroke-width="6"
|
||||
/>
|
||||
<view class="text">
|
||||
<view>{{uploaded}} / {{uploadTotal}}</view>
|
||||
<view>{{uploadSpeed}}</view>
|
||||
<view wx:if="{{isSaving}}" class="uploading">
|
||||
<progress
|
||||
class="progress"
|
||||
percent="{{uploadProgress}}"
|
||||
stroke-width="6"
|
||||
/>
|
||||
<view class="text">
|
||||
<view>{{uploaded}} / {{uploadTotal}}</view>
|
||||
<view>{{uploadSpeed}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 控制按钮 -->
|
||||
<view class="ctrl">
|
||||
<!-- 创建模式 -->
|
||||
<block wx:if="{{mode === 'create'}}">
|
||||
<t-button
|
||||
class="clear"
|
||||
theme="danger"
|
||||
variant="outline"
|
||||
disabled="{{isSaving}}"
|
||||
bind:tap="clearMedia"
|
||||
disabled="{{mediaList.length === 0}}"
|
||||
>清空已选</t-button>
|
||||
<t-button
|
||||
class="submit"
|
||||
theme="primary"
|
||||
bind:tap="submit"
|
||||
disabled="{{(!idea && mediaList.length === 0) || isSaving}}"
|
||||
>提交</t-button>
|
||||
</block>
|
||||
<!-- 编辑模式 -->
|
||||
<block wx:else>
|
||||
<t-button
|
||||
class="delete"
|
||||
theme="danger"
|
||||
bind:tap="deleteJournal"
|
||||
disabled="{{isSaving}}"
|
||||
>删除记录</t-button>
|
||||
<t-button
|
||||
class="save"
|
||||
theme="primary"
|
||||
bind:tap="submit"
|
||||
disabled="{{(!idea && mediaList.length === 0 && newMediaList.length === 0) || isSaving}}"
|
||||
>保存</t-button>
|
||||
</block>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<!-- 删除对话框(仅编辑模式) -->
|
||||
<t-dialog
|
||||
wx:if="{{mode === 'edit'}}"
|
||||
visible="{{deleteDialogVisible}}"
|
||||
title="删除记录"
|
||||
confirm-btn="{{ {content: '删除', variant: 'text', theme: 'danger'} }}"
|
||||
cancel-btn="取消"
|
||||
bind:confirm="confirmDelete"
|
||||
bind:cancel="cancelDelete"
|
||||
>
|
||||
<view slot="content" class="delete-dialog">
|
||||
<view class="tips">
|
||||
<text>此记录的照片和视频也会同步删除,删除后无法恢复,请输入 "</text>
|
||||
<text style="color: var(--theme-error)">确认删除</text>
|
||||
<text>" 以继续</text>
|
||||
<!-- 控制按钮 -->
|
||||
<view class="ctrl">
|
||||
<!-- 创建模式 -->
|
||||
<block wx:if="{{mode === 'create'}}">
|
||||
<t-button
|
||||
class="clear"
|
||||
theme="danger"
|
||||
variant="outline"
|
||||
disabled="{{isSaving}}"
|
||||
bind:tap="clearMedia"
|
||||
disabled="{{mediaList.length === 0}}"
|
||||
>清空已选</t-button>
|
||||
<t-button
|
||||
class="submit"
|
||||
theme="primary"
|
||||
bind:tap="submit"
|
||||
disabled="{{(!idea && mediaList.length === 0) || isSaving}}"
|
||||
>提交</t-button>
|
||||
</block>
|
||||
<!-- 编辑模式 -->
|
||||
<block wx:else>
|
||||
<t-button
|
||||
class="delete"
|
||||
theme="danger"
|
||||
bind:tap="deleteJournal"
|
||||
disabled="{{isSaving}}"
|
||||
>删除记录</t-button>
|
||||
<t-button
|
||||
class="save"
|
||||
theme="primary"
|
||||
bind:tap="submit"
|
||||
disabled="{{(!idea && mediaList.length === 0 && newMediaList.length === 0) || isSaving}}"
|
||||
>保存</t-button>
|
||||
</block>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
<t-input model:value="{{deleteConfirmText}}" placeholder="请输入:确认删除" />
|
||||
</scroll-view>
|
||||
<!-- 删除对话框(仅编辑模式) -->
|
||||
<t-dialog
|
||||
wx:if="{{mode === 'edit'}}"
|
||||
visible="{{deleteDialogVisible}}"
|
||||
title="删除记录"
|
||||
confirm-btn="{{ {content: '删除', variant: 'text', theme: 'danger'} }}"
|
||||
cancel-btn="取消"
|
||||
bind:confirm="confirmDelete"
|
||||
bind:cancel="cancelDelete"
|
||||
>
|
||||
<view slot="content" class="delete-dialog">
|
||||
<view class="tips">
|
||||
<text>此记录的照片和视频也会同步删除,删除后无法恢复,请输入 "</text>
|
||||
<text style="color: var(--theme-error)">确认删除</text>
|
||||
<text>" 以继续</text>
|
||||
</view>
|
||||
<t-input model:value="{{deleteConfirmText}}" placeholder="请输入:确认删除" />
|
||||
</view>
|
||||
</t-dialog>
|
||||
</block>
|
||||
<block wx:elif="{{permissionChecked}}">
|
||||
<view class="no-permission">
|
||||
<t-empty icon="error-circle" description="无权限操作" />
|
||||
</view>
|
||||
</t-dialog>
|
||||
</block>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-empty": "tdesign-miniprogram/empty/empty",
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar"
|
||||
},
|
||||
"disableScroll": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,3 +64,14 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
page {
|
||||
.no-permission {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
background: var(--td-bg-color-page);
|
||||
min-height: 100vh;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// 备忘录页面逻辑
|
||||
import { ToolApi } from "../../../../api/ToolApi";
|
||||
import Permission from "../../../../utils/Permission";
|
||||
|
||||
type EditorInputEvent = WechatMiniprogram.CustomEvent<{
|
||||
html?: string;
|
||||
@@ -16,6 +17,8 @@ interface MemoData {
|
||||
isEditorReady: boolean;
|
||||
contentHtml: string;
|
||||
contentText: string;
|
||||
canUpload: boolean;
|
||||
permissionChecked: boolean;
|
||||
}
|
||||
|
||||
Page({
|
||||
@@ -28,13 +31,19 @@ Page({
|
||||
isSaving: false,
|
||||
isEditorReady: false,
|
||||
contentHtml: "",
|
||||
contentText: ""
|
||||
contentText: "",
|
||||
canUpload: false,
|
||||
permissionChecked: false
|
||||
},
|
||||
editorCtx: null as WechatMiniprogram.EditorContext | null,
|
||||
pendingHtml: "",
|
||||
hasSavedOnLeave: false,
|
||||
hasLoadFailed: false,
|
||||
async onLoad() {
|
||||
const canUpload = await this.ensureUploadPermission();
|
||||
if (!canUpload) {
|
||||
return;
|
||||
}
|
||||
const platform = wx.getSystemInfoSync().platform;
|
||||
const isIOS = platform === "ios";
|
||||
this.setData({ isIOS });
|
||||
@@ -46,11 +55,46 @@ Page({
|
||||
this.hasSavedOnLeave = false;
|
||||
},
|
||||
async onUnload() {
|
||||
if (!this.data.canUpload) {
|
||||
return;
|
||||
}
|
||||
await this.saveMemoOnLeave();
|
||||
},
|
||||
async onHide() {
|
||||
if (!this.data.canUpload) {
|
||||
return;
|
||||
}
|
||||
await this.saveMemoOnLeave();
|
||||
},
|
||||
async ensureUploadPermission(): Promise<boolean> {
|
||||
const cached = Permission.getCachedUploadPermission();
|
||||
if (cached !== null) {
|
||||
this.setData({
|
||||
canUpload: cached,
|
||||
permissionChecked: true
|
||||
});
|
||||
if (!cached) {
|
||||
this.redirectNoPermission();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const canUpload = await Permission.checkAndCacheUploadPermission();
|
||||
this.setData({
|
||||
canUpload,
|
||||
permissionChecked: true
|
||||
});
|
||||
if (!canUpload) {
|
||||
this.redirectNoPermission();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
redirectNoPermission() {
|
||||
wx.switchTab({
|
||||
url: "/pages/main/tabs/journal/index"
|
||||
});
|
||||
},
|
||||
bindKeyboardHeightChange() {
|
||||
let keyboardHeight = 0;
|
||||
wx.onKeyboardHeightChange((res) => {
|
||||
@@ -159,4 +203,4 @@ Page({
|
||||
this.setData({ isSaving: false });
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,65 +1,72 @@
|
||||
<!-- 备忘录页面 -->
|
||||
<view class="custom-navbar">
|
||||
<t-navbar class="custom-navbar" title="备忘录" left-arrow placeholder />
|
||||
</view>
|
||||
<view class="memo setting-bg">
|
||||
<view class="content">
|
||||
<view class="container" style="height:{{editorHeight}}px;">
|
||||
<editor
|
||||
id="memo-editor"
|
||||
class="editor"
|
||||
placeholder="{{placeholder}}"
|
||||
bindready="onEditorReady"
|
||||
bindinput="onEditorInput"
|
||||
bindstatuschange="onStatusChange"
|
||||
show-img-size="{{false}}"
|
||||
show-img-toolbar="{{false}}"
|
||||
show-img-resize="{{false}}"
|
||||
/>
|
||||
</view>
|
||||
<view
|
||||
class="toolbar"
|
||||
catchtouchend="format"
|
||||
hidden="{{0 < keyboardHeight ? false : true}}"
|
||||
style="bottom: {{isIOS ? keyboardHeight : 0}}px"
|
||||
>
|
||||
<text
|
||||
class="icon {{formats.header === 2 ? 'active' : ''}}"
|
||||
data-name="header"
|
||||
data-value="{{2}}"
|
||||
>H2</text>
|
||||
<text
|
||||
class="icon {{formats.header === 3 ? 'active' : ''}}"
|
||||
data-name="header"
|
||||
data-value="{{3}}"
|
||||
>H3</text>
|
||||
<t-icon
|
||||
class="icon {{formats.bold ? 'active' : ''}}"
|
||||
name="textformat-bold"
|
||||
data-name="bold"
|
||||
/>
|
||||
<t-icon
|
||||
class="icon {{formats.italic ? 'active' : ''}}"
|
||||
name="textformat-italic"
|
||||
data-name="italic"
|
||||
/>
|
||||
<t-icon
|
||||
class="icon {{formats.underline ? 'active' : ''}}"
|
||||
name="textformat-underline"
|
||||
data-name="underline"
|
||||
/>
|
||||
<t-icon
|
||||
class="icon"
|
||||
name="task"
|
||||
data-name="list"
|
||||
data-value="check"
|
||||
/>
|
||||
<t-icon
|
||||
class="icon {{formats.list === 'bullet' ? 'active' : ''}}"
|
||||
name="bulletpoint"
|
||||
data-name="list"
|
||||
data-value="bullet"
|
||||
/>
|
||||
<block wx:if="{{canUpload}}">
|
||||
<view class="custom-navbar">
|
||||
<t-navbar class="custom-navbar" title="备忘录" left-arrow placeholder />
|
||||
</view>
|
||||
<view class="memo setting-bg">
|
||||
<view class="content">
|
||||
<view class="container" style="height:{{editorHeight}}px;">
|
||||
<editor
|
||||
id="memo-editor"
|
||||
class="editor"
|
||||
placeholder="{{placeholder}}"
|
||||
bindready="onEditorReady"
|
||||
bindinput="onEditorInput"
|
||||
bindstatuschange="onStatusChange"
|
||||
show-img-size="{{false}}"
|
||||
show-img-toolbar="{{false}}"
|
||||
show-img-resize="{{false}}"
|
||||
/>
|
||||
</view>
|
||||
<view
|
||||
class="toolbar"
|
||||
catchtouchend="format"
|
||||
hidden="{{0 < keyboardHeight ? false : true}}"
|
||||
style="bottom: {{isIOS ? keyboardHeight : 0}}px"
|
||||
>
|
||||
<text
|
||||
class="icon {{formats.header === 2 ? 'active' : ''}}"
|
||||
data-name="header"
|
||||
data-value="{{2}}"
|
||||
>H2</text>
|
||||
<text
|
||||
class="icon {{formats.header === 3 ? 'active' : ''}}"
|
||||
data-name="header"
|
||||
data-value="{{3}}"
|
||||
>H3</text>
|
||||
<t-icon
|
||||
class="icon {{formats.bold ? 'active' : ''}}"
|
||||
name="textformat-bold"
|
||||
data-name="bold"
|
||||
/>
|
||||
<t-icon
|
||||
class="icon {{formats.italic ? 'active' : ''}}"
|
||||
name="textformat-italic"
|
||||
data-name="italic"
|
||||
/>
|
||||
<t-icon
|
||||
class="icon {{formats.underline ? 'active' : ''}}"
|
||||
name="textformat-underline"
|
||||
data-name="underline"
|
||||
/>
|
||||
<t-icon
|
||||
class="icon"
|
||||
name="task"
|
||||
data-name="list"
|
||||
data-value="check"
|
||||
/>
|
||||
<t-icon
|
||||
class="icon {{formats.list === 'bullet' ? 'active' : ''}}"
|
||||
name="bulletpoint"
|
||||
data-name="list"
|
||||
data-value="bullet"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:elif="{{permissionChecked}}">
|
||||
<view class="no-permission">
|
||||
<t-empty icon="error-circle" description="无权限操作" />
|
||||
</view>
|
||||
</block>
|
||||
|
||||
@@ -61,4 +61,11 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
min-height: 60vh;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
<t-navbar class="custom-navbar" title="专拍" left-arrow placeholder />
|
||||
</view>
|
||||
<view class="portfolio-list">
|
||||
<view wx:if="{{list.length === 0}}" class="empty-state">
|
||||
<t-empty icon="image-error" description="暂无专拍照片或视频" />
|
||||
</view>
|
||||
<t-collapse class="collapse" expandMutex expandIcon>
|
||||
<t-collapse-panel
|
||||
class="panel"
|
||||
@@ -30,4 +33,4 @@
|
||||
</view>
|
||||
</t-collapse-panel>
|
||||
</t-collapse>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="label">版本:</text>
|
||||
<text>1.7.0</text>
|
||||
<text>1.7.3</text>
|
||||
</view>
|
||||
<view class="item copyright">
|
||||
<text>{{copyright}}</text>
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"t-cell": "tdesign-miniprogram/cell/cell",
|
||||
"t-popup": "tdesign-miniprogram/popup/popup",
|
||||
"t-radio": "tdesign-miniprogram/radio/radio",
|
||||
"t-empty": "tdesign-miniprogram/empty/empty",
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"t-button": "tdesign-miniprogram/button/button",
|
||||
"t-checkbox": "tdesign-miniprogram/checkbox/checkbox",
|
||||
|
||||
@@ -100,6 +100,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
min-height: 60vh;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.t-popup--bottom {
|
||||
@@ -187,4 +194,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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,10 @@
|
||||
>删除已选</t-button>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{isUploading}}" class="uploading">
|
||||
<view wx:if="{{!canUpload && list.length === 0}}" class="empty-state">
|
||||
<t-empty icon="image-error" description="暂无临时照片或视频" />
|
||||
</view>
|
||||
<view wx:if="{{canUpload && isUploading}}" class="uploading">
|
||||
<progress
|
||||
class="progress"
|
||||
percent="{{uploadProgress}}"
|
||||
@@ -81,6 +84,7 @@
|
||||
</view>
|
||||
</view>
|
||||
<t-popup
|
||||
wx:if="{{canUpload}}"
|
||||
class="archive-popup"
|
||||
visible="{{isVisibleArchivePopup}}"
|
||||
placement="bottom"
|
||||
@@ -190,4 +194,4 @@
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</t-popup>
|
||||
</t-popup>
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { TravelApi } from "../../../../api/TravelApi";
|
||||
import { TravelLocationApi } from "../../../../api/TravelLocationApi";
|
||||
import config from "../../../../config/index";
|
||||
import { Travel, TravelStatusLabel, TravelStatusIcon, TransportationTypeLabel, TravelLocation, TravelLocationTypeLabel, TravelLocationTypeIcon, TransportationTypeIcon, TravelLocationType } from "../../../../types/Travel";
|
||||
import Permission from "../../../../utils/Permission";
|
||||
|
||||
interface TravelLocationView extends TravelLocation {
|
||||
/** 预览图 */
|
||||
@@ -42,6 +43,8 @@ interface TravelDetailData {
|
||||
deleteDialogVisible: boolean;
|
||||
/** 删除确认文本 */
|
||||
deleteConfirmText: string;
|
||||
/** 是否允许上传 */
|
||||
canUpload: boolean;
|
||||
}
|
||||
|
||||
Page({
|
||||
@@ -60,7 +63,8 @@ Page({
|
||||
locationTypes: ["全部", ...Object.values(TravelLocationTypeLabel)],
|
||||
selectedLocationTypeIndex: 0,
|
||||
deleteDialogVisible: false,
|
||||
deleteConfirmText: ""
|
||||
deleteConfirmText: "",
|
||||
canUpload: false
|
||||
},
|
||||
|
||||
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) {
|
||||
this.fetchLocations(this.data.travelId);
|
||||
await this.fetchLocations(this.data.travelId);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<!--pages/main/travel/detail/index.wxml-->
|
||||
<view class="custom-navbar">
|
||||
<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" />
|
||||
</view>
|
||||
</t-navbar>
|
||||
@@ -61,7 +61,14 @@
|
||||
</view>
|
||||
</picker>
|
||||
</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 wx:if="{{isLoadingLocations}}" class="loading">
|
||||
<t-loading slot="title" theme="dots" size="40rpx" />
|
||||
@@ -117,6 +124,7 @@
|
||||
<!-- 操作按钮 -->
|
||||
<view class="section action">
|
||||
<t-button
|
||||
wx:if="{{canUpload}}"
|
||||
theme="danger"
|
||||
variant="outline"
|
||||
size="large"
|
||||
@@ -127,6 +135,7 @@
|
||||
删除
|
||||
</t-button>
|
||||
<t-button
|
||||
wx:if="{{canUpload}}"
|
||||
theme="primary"
|
||||
size="large"
|
||||
icon="edit"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"t-loading": "tdesign-miniprogram/loading/loading",
|
||||
"t-stepper": "tdesign-miniprogram/stepper/stepper",
|
||||
"t-textarea": "tdesign-miniprogram/textarea/textarea",
|
||||
"t-empty": "tdesign-miniprogram/empty/empty",
|
||||
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group"
|
||||
},
|
||||
"styleIsolation": "shared"
|
||||
|
||||
@@ -110,3 +110,14 @@
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
}
|
||||
|
||||
page {
|
||||
.no-permission {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
background: var(--td-bg-color-page);
|
||||
min-height: 100vh;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import Time from "../../../../utils/Time";
|
||||
import { TravelApi } from "../../../../api/TravelApi";
|
||||
import { TravelStatus, TransportationType } from "../../../../types/Travel";
|
||||
import Permission from "../../../../utils/Permission";
|
||||
|
||||
interface TravelEditorData {
|
||||
/** 模式:create 或 edit */
|
||||
@@ -43,6 +44,10 @@ interface TravelEditorData {
|
||||
deleteDialogVisible: boolean;
|
||||
/** 删除确认文本 */
|
||||
deleteConfirmText: string;
|
||||
/** 是否拥有上传权限 */
|
||||
canUpload: boolean;
|
||||
/** 是否已检查权限 */
|
||||
permissionChecked: boolean;
|
||||
}
|
||||
|
||||
Page({
|
||||
@@ -76,9 +81,15 @@ Page({
|
||||
{ label: "已完成", value: TravelStatus.COMPLETED }
|
||||
],
|
||||
deleteDialogVisible: false,
|
||||
deleteConfirmText: ""
|
||||
deleteConfirmText: "",
|
||||
canUpload: false,
|
||||
permissionChecked: false
|
||||
},
|
||||
onLoad(options: any) {
|
||||
async onLoad(options: any) {
|
||||
const canUpload = await this.ensureUploadPermission();
|
||||
if (!canUpload) {
|
||||
return;
|
||||
}
|
||||
// 判断模式:有 ID 是编辑,无 ID 是创建
|
||||
const id = options.id ? parseInt(options.id) : undefined;
|
||||
|
||||
@@ -89,7 +100,7 @@ Page({
|
||||
id,
|
||||
isLoading: true
|
||||
});
|
||||
this.loadTravelDetail(id);
|
||||
await this.loadTravelDetail(id);
|
||||
} else {
|
||||
// 创建模式
|
||||
this.setData({
|
||||
@@ -105,6 +116,35 @@ Page({
|
||||
});
|
||||
}
|
||||
},
|
||||
async ensureUploadPermission(): Promise<boolean> {
|
||||
const cached = Permission.getCachedUploadPermission();
|
||||
if (cached !== null) {
|
||||
this.setData({
|
||||
canUpload: cached,
|
||||
permissionChecked: true
|
||||
});
|
||||
if (!cached) {
|
||||
this.redirectNoPermission();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const canUpload = await Permission.checkAndCacheUploadPermission();
|
||||
this.setData({
|
||||
canUpload,
|
||||
permissionChecked: true
|
||||
});
|
||||
if (!canUpload) {
|
||||
this.redirectNoPermission();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
redirectNoPermission() {
|
||||
wx.switchTab({
|
||||
url: "/pages/main/tabs/journal/index"
|
||||
});
|
||||
},
|
||||
/** 加载出行详情(编辑模式) */
|
||||
async loadTravelDetail(id: number) {
|
||||
wx.showLoading({ title: "加载中...", mask: true });
|
||||
|
||||
@@ -1,154 +1,161 @@
|
||||
<!--pages/main/travel/editor/index.wxml-->
|
||||
<t-navbar title="{{mode === 'create' ? '新建出行' : '编辑出行'}}" placeholder>
|
||||
<text slot="left" bindtap="cancel">取消</text>
|
||||
</t-navbar>
|
||||
<block wx:if="{{canUpload}}">
|
||||
<t-navbar title="{{mode === 'create' ? '新建出行' : '编辑出行'}}" placeholder>
|
||||
<text slot="left" bindtap="cancel">取消</text>
|
||||
</t-navbar>
|
||||
|
||||
<scroll-view class="travel-editor setting-bg" type="custom" scroll-y show-scrollbar="{{false}}">
|
||||
<view class="content">
|
||||
<view wx:if="{{isLoading}}" class="loading">
|
||||
<t-loading theme="dots" size="40rpx" />
|
||||
<text class="loading-text">加载中...</text>
|
||||
</view>
|
||||
<block wx:else>
|
||||
<t-cell-group class="section">
|
||||
<view slot="title" class="title">基本信息</view>
|
||||
<t-input
|
||||
class="input"
|
||||
placeholder="请输入出行标题"
|
||||
model:value="{{title}}"
|
||||
maxlength="50"
|
||||
>
|
||||
<text slot="label">标题</text>
|
||||
</t-input>
|
||||
<t-textarea
|
||||
class="textarea"
|
||||
placeholder="添加详细说明(选填)"
|
||||
model:value="{{content}}"
|
||||
maxlength="500"
|
||||
indicator
|
||||
>
|
||||
<text slot="label">内容</text>
|
||||
</t-textarea>
|
||||
</t-cell-group>
|
||||
<t-cell-group class="section">
|
||||
<view slot="title" class="title">详细信息</view>
|
||||
<t-cell class="travel-at" title="出行时间">
|
||||
<view slot="right-icon" class="travel-at-content">
|
||||
<picker wx:if="{{!travelAtUndecided}}" class="picker" mode="date" model:value="{{date}}">
|
||||
<view slot="content" class="slot">
|
||||
<t-icon name="calendar" size="20px" class="icon" />
|
||||
<text>{{date}}</text>
|
||||
<scroll-view class="travel-editor setting-bg" type="custom" scroll-y show-scrollbar="{{false}}">
|
||||
<view class="content">
|
||||
<view wx:if="{{isLoading}}" class="loading">
|
||||
<t-loading theme="dots" size="40rpx" />
|
||||
<text class="loading-text">加载中...</text>
|
||||
</view>
|
||||
<block wx:else>
|
||||
<t-cell-group class="section">
|
||||
<view slot="title" class="title">基本信息</view>
|
||||
<t-input
|
||||
class="input"
|
||||
placeholder="请输入出行标题"
|
||||
model:value="{{title}}"
|
||||
maxlength="50"
|
||||
>
|
||||
<text slot="label">标题</text>
|
||||
</t-input>
|
||||
<t-textarea
|
||||
class="textarea"
|
||||
placeholder="添加详细说明(选填)"
|
||||
model:value="{{content}}"
|
||||
maxlength="500"
|
||||
indicator
|
||||
>
|
||||
<text slot="label">内容</text>
|
||||
</t-textarea>
|
||||
</t-cell-group>
|
||||
<t-cell-group class="section">
|
||||
<view slot="title" class="title">详细信息</view>
|
||||
<t-cell class="travel-at" title="出行时间">
|
||||
<view slot="right-icon" class="travel-at-content">
|
||||
<picker wx:if="{{!travelAtUndecided}}" class="picker" mode="date" model:value="{{date}}">
|
||||
<view slot="content" class="slot">
|
||||
<t-icon name="calendar" size="20px" class="icon" />
|
||||
<text>{{date}}</text>
|
||||
</view>
|
||||
</picker>
|
||||
<view wx:else class="slot" bindtap="selectTravelAt">
|
||||
<text class="undecided-text">未定</text>
|
||||
</view>
|
||||
</picker>
|
||||
<view wx:else class="slot" bindtap="selectTravelAt">
|
||||
<text class="undecided-text">未定</text>
|
||||
<t-icon
|
||||
wx:if="{{!travelAtUndecided}}"
|
||||
name="close-circle-filled"
|
||||
size="20px"
|
||||
class="clear-icon"
|
||||
bindtap="clearTravelAt"
|
||||
/>
|
||||
</view>
|
||||
<t-icon
|
||||
wx:if="{{!travelAtUndecided}}"
|
||||
name="close-circle-filled"
|
||||
size="20px"
|
||||
class="clear-icon"
|
||||
bindtap="clearTravelAt"
|
||||
/>
|
||||
</view>
|
||||
</t-cell>
|
||||
<t-cell title="出行天数" class="days {{daysUndecided ? 'undecided' : 'decided'}}">
|
||||
<view slot="right-icon" class="days-content">
|
||||
<t-stepper
|
||||
wx:if="{{!daysUndecided}}"
|
||||
theme="filled"
|
||||
model:value="{{days}}"
|
||||
size="large"
|
||||
min="{{1}}"
|
||||
max="{{999}}"
|
||||
t-class="stepper"
|
||||
/>
|
||||
<view wx:else class="slot" bindtap="selectDays">
|
||||
<text class="undecided-text">未定</text>
|
||||
</t-cell>
|
||||
<t-cell title="出行天数" class="days {{daysUndecided ? 'undecided' : 'decided'}}">
|
||||
<view slot="right-icon" class="days-content">
|
||||
<t-stepper
|
||||
wx:if="{{!daysUndecided}}"
|
||||
theme="filled"
|
||||
model:value="{{days}}"
|
||||
size="large"
|
||||
min="{{1}}"
|
||||
max="{{999}}"
|
||||
t-class="stepper"
|
||||
/>
|
||||
<view wx:else class="slot" bindtap="selectDays">
|
||||
<text class="undecided-text">未定</text>
|
||||
</view>
|
||||
<t-icon
|
||||
wx:if="{{!daysUndecided}}"
|
||||
name="close-circle-filled"
|
||||
size="20px"
|
||||
class="clear-icon"
|
||||
bindtap="clearDays"
|
||||
/>
|
||||
</view>
|
||||
<t-icon
|
||||
wx:if="{{!daysUndecided}}"
|
||||
name="close-circle-filled"
|
||||
size="20px"
|
||||
class="clear-icon"
|
||||
bindtap="clearDays"
|
||||
/>
|
||||
</view>
|
||||
</t-cell>
|
||||
<picker
|
||||
mode="selector"
|
||||
range="{{transportationTypes}}"
|
||||
range-key="label"
|
||||
value="{{transportationTypeIndex}}"
|
||||
bindchange="onChangeTransportationType"
|
||||
>
|
||||
<t-cell title="交通方式" arrow>
|
||||
<view slot="note" class="note">{{transportationTypes[transportationTypeIndex].label}}</view>
|
||||
</t-cell>
|
||||
</picker>
|
||||
<picker
|
||||
mode="selector"
|
||||
range="{{statuses}}"
|
||||
range-key="label"
|
||||
value="{{statusIndex}}"
|
||||
bindchange="onChangeStatus"
|
||||
>
|
||||
<t-cell title="状态" arrow>
|
||||
<view slot="note" class="note">{{statuses[statusIndex].label}}</view>
|
||||
</t-cell>
|
||||
</picker>
|
||||
</t-cell-group>
|
||||
<view wx:if="{{mode === 'create'}}" class="submit-section">
|
||||
<t-button
|
||||
theme="primary"
|
||||
size="large"
|
||||
block
|
||||
bind:tap="submit"
|
||||
disabled="{{isSaving}}"
|
||||
>
|
||||
创建出行
|
||||
</t-button>
|
||||
</view>
|
||||
<view wx:else class="submit-section horizontal">
|
||||
<t-button
|
||||
theme="danger"
|
||||
variant="outline"
|
||||
size="large"
|
||||
icon="delete"
|
||||
t-class="delete-btn"
|
||||
bind:tap="deleteTravel"
|
||||
>
|
||||
删除
|
||||
</t-button>
|
||||
<t-button
|
||||
theme="primary"
|
||||
size="large"
|
||||
t-class="save-btn"
|
||||
bind:tap="submit"
|
||||
disabled="{{isSaving}}"
|
||||
>
|
||||
保存修改
|
||||
</t-button>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 删除确认对话框 -->
|
||||
<t-dialog
|
||||
visible="{{deleteDialogVisible}}"
|
||||
title="删除出行计划"
|
||||
confirm-btn="{{ {content: '删除', variant: 'text', theme: 'danger'} }}"
|
||||
cancel-btn="取消"
|
||||
bind:confirm="confirmDelete"
|
||||
bind:cancel="cancelDelete"
|
||||
>
|
||||
<view slot="content" class="delete-dialog">
|
||||
<view class="tips">
|
||||
<text>此计划的地点、图片和视频也会同步删除,删除后无法恢复,请输入 "</text>
|
||||
<text style="color: var(--theme-error)">确认删除</text>
|
||||
<text>" 以继续</text>
|
||||
<picker
|
||||
mode="selector"
|
||||
range="{{transportationTypes}}"
|
||||
range-key="label"
|
||||
value="{{transportationTypeIndex}}"
|
||||
bindchange="onChangeTransportationType"
|
||||
>
|
||||
<t-cell title="交通方式" arrow>
|
||||
<view slot="note" class="note">{{transportationTypes[transportationTypeIndex].label}}</view>
|
||||
</t-cell>
|
||||
</picker>
|
||||
<picker
|
||||
mode="selector"
|
||||
range="{{statuses}}"
|
||||
range-key="label"
|
||||
value="{{statusIndex}}"
|
||||
bindchange="onChangeStatus"
|
||||
>
|
||||
<t-cell title="状态" arrow>
|
||||
<view slot="note" class="note">{{statuses[statusIndex].label}}</view>
|
||||
</t-cell>
|
||||
</picker>
|
||||
</t-cell-group>
|
||||
<view wx:if="{{mode === 'create'}}" class="submit-section">
|
||||
<t-button
|
||||
theme="primary"
|
||||
size="large"
|
||||
block
|
||||
bind:tap="submit"
|
||||
disabled="{{isSaving}}"
|
||||
>
|
||||
创建出行
|
||||
</t-button>
|
||||
</view>
|
||||
<view wx:else class="submit-section horizontal">
|
||||
<t-button
|
||||
theme="danger"
|
||||
variant="outline"
|
||||
size="large"
|
||||
icon="delete"
|
||||
t-class="delete-btn"
|
||||
bind:tap="deleteTravel"
|
||||
>
|
||||
删除
|
||||
</t-button>
|
||||
<t-button
|
||||
theme="primary"
|
||||
size="large"
|
||||
t-class="save-btn"
|
||||
bind:tap="submit"
|
||||
disabled="{{isSaving}}"
|
||||
>
|
||||
保存修改
|
||||
</t-button>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
<t-input placeholder="请输入:确认删除" model:value="{{deleteConfirmText}}" />
|
||||
</scroll-view>
|
||||
|
||||
<!-- 删除确认对话框 -->
|
||||
<t-dialog
|
||||
visible="{{deleteDialogVisible}}"
|
||||
title="删除出行计划"
|
||||
confirm-btn="{{ {content: '删除', variant: 'text', theme: 'danger'} }}"
|
||||
cancel-btn="取消"
|
||||
bind:confirm="confirmDelete"
|
||||
bind:cancel="cancelDelete"
|
||||
>
|
||||
<view slot="content" class="delete-dialog">
|
||||
<view class="tips">
|
||||
<text>此计划的地点、图片和视频也会同步删除,删除后无法恢复,请输入 "</text>
|
||||
<text style="color: var(--theme-error)">确认删除</text>
|
||||
<text>" 以继续</text>
|
||||
</view>
|
||||
<t-input placeholder="请输入:确认删除" model:value="{{deleteConfirmText}}" />
|
||||
</view>
|
||||
</t-dialog>
|
||||
</block>
|
||||
<block wx:elif="{{permissionChecked}}">
|
||||
<view class="no-permission">
|
||||
<t-empty icon="error-circle" description="无权限操作" />
|
||||
</view>
|
||||
</t-dialog>
|
||||
</block>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { TravelLocation, TravelLocationTypeIcon, TravelLocationTypeLabel } from
|
||||
import { MediaAttachType, PreviewImageMetadata } from "../../../../types/Attachment";
|
||||
import { MapMarker, MediaItem, MediaItemType } from "../../../../types/UI";
|
||||
import Toolkit from "../../../../utils/Toolkit";
|
||||
import Permission from "../../../../utils/Permission";
|
||||
|
||||
interface TravelLocationView extends TravelLocation {
|
||||
/** 媒体列表 */
|
||||
@@ -35,6 +36,8 @@ interface TravelLocationDetailData {
|
||||
deleteDialogVisible: boolean;
|
||||
/** 删除确认文本 */
|
||||
deleteConfirmText: string;
|
||||
/** 是否允许上传 */
|
||||
canUpload: boolean;
|
||||
}
|
||||
|
||||
Page({
|
||||
@@ -51,7 +54,8 @@ Page({
|
||||
},
|
||||
mapMarkers: [],
|
||||
deleteDialogVisible: false,
|
||||
deleteConfirmText: ""
|
||||
deleteConfirmText: "",
|
||||
canUpload: false
|
||||
},
|
||||
|
||||
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) {
|
||||
this.fetchDetail(this.data.locationId);
|
||||
await this.fetchDetail(this.data.locationId);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<!--pages/main/travel/location-detail/index.wxml-->
|
||||
<view class="custom-navbar">
|
||||
<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" />
|
||||
</view>
|
||||
</t-navbar>
|
||||
@@ -120,7 +120,7 @@
|
||||
</t-button>
|
||||
</view>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="section action">
|
||||
<view wx:if="{{canUpload}}" class="section action">
|
||||
<t-button
|
||||
theme="danger"
|
||||
variant="outline"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"t-loading": "tdesign-miniprogram/loading/loading",
|
||||
"t-stepper": "tdesign-miniprogram/stepper/stepper",
|
||||
"t-textarea": "tdesign-miniprogram/textarea/textarea",
|
||||
"t-empty": "tdesign-miniprogram/empty/empty",
|
||||
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group"
|
||||
},
|
||||
"styleIsolation": "shared"
|
||||
|
||||
@@ -199,3 +199,14 @@
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
}
|
||||
|
||||
page {
|
||||
.no-permission {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
background: var(--td-bg-color-page);
|
||||
min-height: 100vh;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { TravelLocationType, TravelLocationTypeLabel } from "../../../../types/T
|
||||
import { MediaAttachType, PreviewImageMetadata } from "../../../../types/Attachment";
|
||||
import config from "../../../../config/index";
|
||||
import { MediaItem, MediaItemType } from "../../../../types/UI";
|
||||
import Permission from "../../../../utils/Permission";
|
||||
|
||||
interface TravelLocationEditorData {
|
||||
/** 模式:create 或 edit */
|
||||
@@ -64,6 +65,10 @@ interface TravelLocationEditorData {
|
||||
deleteConfirmText: string;
|
||||
/** 媒体类型枚举 */
|
||||
mediaItemTypeEnum: any;
|
||||
/** 是否拥有上传权限 */
|
||||
canUpload: boolean;
|
||||
/** 是否已检查权限 */
|
||||
permissionChecked: boolean;
|
||||
}
|
||||
|
||||
Page({
|
||||
@@ -105,10 +110,16 @@ Page({
|
||||
],
|
||||
locationTypeIndex: 0,
|
||||
deleteDialogVisible: false,
|
||||
deleteConfirmText: ""
|
||||
deleteConfirmText: "",
|
||||
canUpload: false,
|
||||
permissionChecked: false
|
||||
},
|
||||
|
||||
onLoad(options: any) {
|
||||
async onLoad(options: any) {
|
||||
const canUpload = await this.ensureUploadPermission();
|
||||
if (!canUpload) {
|
||||
return;
|
||||
}
|
||||
// 获取 travelId(必填)
|
||||
const travelId = options.travelId ? parseInt(options.travelId) : 0;
|
||||
if (!travelId) {
|
||||
@@ -133,7 +144,7 @@ Page({
|
||||
travelId,
|
||||
isLoading: true
|
||||
});
|
||||
this.loadLocationDetail(id);
|
||||
await this.loadLocationDetail(id);
|
||||
} else {
|
||||
// 创建模式
|
||||
this.setData({
|
||||
@@ -143,6 +154,35 @@ Page({
|
||||
});
|
||||
}
|
||||
},
|
||||
async ensureUploadPermission(): Promise<boolean> {
|
||||
const cached = Permission.getCachedUploadPermission();
|
||||
if (cached !== null) {
|
||||
this.setData({
|
||||
canUpload: cached,
|
||||
permissionChecked: true
|
||||
});
|
||||
if (!cached) {
|
||||
this.redirectNoPermission();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
const canUpload = await Permission.checkAndCacheUploadPermission();
|
||||
this.setData({
|
||||
canUpload,
|
||||
permissionChecked: true
|
||||
});
|
||||
if (!canUpload) {
|
||||
this.redirectNoPermission();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
redirectNoPermission() {
|
||||
wx.switchTab({
|
||||
url: "/pages/main/tabs/journal/index"
|
||||
});
|
||||
},
|
||||
|
||||
/** 加载地点详情(编辑模式) */
|
||||
async loadLocationDetail(id: number) {
|
||||
|
||||
@@ -1,168 +1,159 @@
|
||||
<!--pages/main/travel/location-editor/index.wxml-->
|
||||
<t-navbar title="{{mode === 'create' ? '添加地点' : '编辑地点'}}" placeholder>
|
||||
<text slot="left" bindtap="cancel">取消</text>
|
||||
</t-navbar>
|
||||
<block wx:if="{{canUpload}}">
|
||||
<t-navbar title="{{mode === 'create' ? '添加地点' : '编辑地点'}}" placeholder>
|
||||
<text slot="left" bindtap="cancel">取消</text>
|
||||
</t-navbar>
|
||||
|
||||
<scroll-view class="travel-location-editor setting-bg" type="custom" scroll-y show-scrollbar="{{false}}">
|
||||
<view class="content">
|
||||
<view wx:if="{{isLoading}}" class="loading">
|
||||
<t-loading theme="dots" size="40rpx" />
|
||||
<text class="text">加载中...</text>
|
||||
</view>
|
||||
<block wx:else>
|
||||
<t-cell-group class="section location">
|
||||
<view slot="title" class="title">位置信息</view>
|
||||
<picker mode="selector" range="{{locationTypes}}" value="{{locationTypeIndex}}" bindchange="onChangeLocationType">
|
||||
<t-cell title="地点类型" arrow>
|
||||
<view slot="note" class="note">{{locationTypes[locationTypeIndex]}}</view>
|
||||
<scroll-view class="travel-location-editor setting-bg" type="custom" scroll-y show-scrollbar="{{false}}">
|
||||
<view class="content">
|
||||
<view wx:if="{{isLoading}}" class="loading">
|
||||
<t-loading theme="dots" size="40rpx" />
|
||||
<text class="text">加载中...</text>
|
||||
</view>
|
||||
<block wx:else>
|
||||
<t-cell-group class="section location">
|
||||
<view slot="title" class="title">位置信息</view>
|
||||
<picker mode="selector" range="{{locationTypes}}" value="{{locationTypeIndex}}" bindchange="onChangeLocationType">
|
||||
<t-cell title="地点类型" arrow>
|
||||
<view slot="note" class="note">{{locationTypes[locationTypeIndex]}}</view>
|
||||
</t-cell>
|
||||
</picker>
|
||||
<t-cell class="value" required arrow bind:click="chooseLocation">
|
||||
<view slot="title" class="title">位置</view>
|
||||
<view slot="note" class="note">{{location}}</view>
|
||||
</t-cell>
|
||||
</picker>
|
||||
<t-cell class="value" required arrow bind:click="chooseLocation">
|
||||
<view slot="title" class="title">位置</view>
|
||||
<view slot="note" class="note">{{location}}</view>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-cell-group class="section">
|
||||
<view slot="title" class="title">基本信息</view>
|
||||
<t-input
|
||||
class="input"
|
||||
placeholder="请输入地点名称"
|
||||
model:value="{{title}}"
|
||||
label="标题"
|
||||
maxlength="50"
|
||||
/>
|
||||
<t-textarea
|
||||
class="textarea"
|
||||
placeholder="添加地点说明(选填)"
|
||||
model:value="{{description}}"
|
||||
maxlength="500"
|
||||
indicator
|
||||
>
|
||||
<text slot="label">说明</text>
|
||||
</t-textarea>
|
||||
</t-cell-group>
|
||||
<t-cell-group class="section">
|
||||
<view slot="title" class="title">详细信息</view>
|
||||
<t-input
|
||||
model:value="{{amount}}"
|
||||
placeholder="0"
|
||||
label="费用"
|
||||
suffix="元"
|
||||
type="digit"
|
||||
align="right"
|
||||
/>
|
||||
<t-cell title="需要身份证">
|
||||
<view slot="right-icon">
|
||||
<switch checked="{{requireIdCard}}" bindchange="onChangeRequireIdCard" />
|
||||
</view>
|
||||
</t-cell>
|
||||
<t-cell title="需要预约">
|
||||
<view slot="right-icon">
|
||||
<switch checked="{{requireAppointment}}" bindchange="onChangeRequireAppointment" />
|
||||
</view>
|
||||
</t-cell>
|
||||
<t-cell title="重要程度" class="rate-cell importance {{importanceUndecided ? 'undecided' : 'decided'}}">
|
||||
<view slot="note">
|
||||
<view class="rate">
|
||||
<t-rate
|
||||
value="{{importance}}"
|
||||
count="{{5}}"
|
||||
size="20px"
|
||||
bind:change="onChangeImportance"
|
||||
/>
|
||||
<t-icon
|
||||
name="close-circle-filled"
|
||||
size="20px"
|
||||
class="clear-icon"
|
||||
bindtap="clearImportance"
|
||||
/>
|
||||
</t-cell-group>
|
||||
<t-cell-group class="section">
|
||||
<view slot="title" class="title">基本信息</view>
|
||||
<t-input
|
||||
class="input"
|
||||
placeholder="请输入地点名称"
|
||||
model:value="{{title}}"
|
||||
label="标题"
|
||||
maxlength="50"
|
||||
/>
|
||||
<t-textarea
|
||||
class="textarea"
|
||||
placeholder="添加地点说明(选填)"
|
||||
model:value="{{description}}"
|
||||
maxlength="500"
|
||||
indicator
|
||||
>
|
||||
<text slot="label">说明</text>
|
||||
</t-textarea>
|
||||
</t-cell-group>
|
||||
<t-cell-group class="section">
|
||||
<view slot="title" class="title">详细信息</view>
|
||||
<t-input
|
||||
model:value="{{amount}}"
|
||||
placeholder="0"
|
||||
label="费用"
|
||||
suffix="元"
|
||||
type="digit"
|
||||
align="right"
|
||||
/>
|
||||
<t-cell title="需要身份证">
|
||||
<view slot="right-icon">
|
||||
<switch checked="{{requireIdCard}}" bindchange="onChangeRequireIdCard" />
|
||||
</view>
|
||||
<view class="text" bindtap="selectImportance">
|
||||
未定
|
||||
</t-cell>
|
||||
<t-cell title="需要预约">
|
||||
<view slot="right-icon">
|
||||
<switch checked="{{requireAppointment}}" bindchange="onChangeRequireAppointment" />
|
||||
</view>
|
||||
</view>
|
||||
</t-cell>
|
||||
<t-cell title="评分" class="rate-cell score {{scoreUndecided ? 'undecided' : 'decided'}}">
|
||||
<view slot="note">
|
||||
<view class="rate">
|
||||
<t-rate
|
||||
value="{{score}}"
|
||||
count="{{5}}"
|
||||
size="20px"
|
||||
bind:change="onChangeScore"
|
||||
/>
|
||||
<t-icon
|
||||
name="close-circle-filled"
|
||||
size="20px"
|
||||
class="clear-icon"
|
||||
bindtap="clearScore"
|
||||
/>
|
||||
</t-cell>
|
||||
<t-cell title="重要程度" class="rate-cell importance {{importanceUndecided ? 'undecided' : 'decided'}}">
|
||||
<view slot="note">
|
||||
<view class="rate">
|
||||
<t-rate
|
||||
value="{{importance}}"
|
||||
count="{{5}}"
|
||||
size="20px"
|
||||
bind:change="onChangeImportance"
|
||||
/>
|
||||
<t-icon
|
||||
name="close-circle-filled"
|
||||
size="20px"
|
||||
class="clear-icon"
|
||||
bindtap="clearImportance"
|
||||
/>
|
||||
</view>
|
||||
<view class="text" bindtap="selectImportance">
|
||||
未定
|
||||
</view>
|
||||
</view>
|
||||
<view class="text" bindtap="selectScore">
|
||||
未定
|
||||
</t-cell>
|
||||
<t-cell title="评分" class="rate-cell score {{scoreUndecided ? 'undecided' : 'decided'}}">
|
||||
<view slot="note">
|
||||
<view class="rate">
|
||||
<t-rate
|
||||
value="{{score}}"
|
||||
count="{{5}}"
|
||||
size="20px"
|
||||
bind:change="onChangeScore"
|
||||
/>
|
||||
<t-icon
|
||||
name="close-circle-filled"
|
||||
size="20px"
|
||||
class="clear-icon"
|
||||
bindtap="clearScore"
|
||||
/>
|
||||
</view>
|
||||
<view class="text" bindtap="selectScore">
|
||||
未定
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-cell-group class="section media">
|
||||
<view slot="title" class="title">图片视频</view>
|
||||
<t-cell>
|
||||
<view slot="title" class="gallery">
|
||||
<!-- 创建模式:mediaList 显示新选择的媒体 -->
|
||||
<block wx:if="{{mode === 'create'}}">
|
||||
<block wx:for="{{mediaList}}" wx:key="index">
|
||||
<view class="item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.path}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-cell-group class="section media">
|
||||
<view slot="title" class="title">图片视频</view>
|
||||
<t-cell>
|
||||
<view slot="title" class="gallery">
|
||||
<!-- 创建模式:mediaList 显示新选择的媒体 -->
|
||||
<block wx:if="{{mode === 'create'}}">
|
||||
<block wx:for="{{mediaList}}" wx:key="index">
|
||||
<view class="item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
src="{{item.thumbPath}}"
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.path}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
<image
|
||||
src="{{item.thumbPath}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
</view>
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
/>
|
||||
</view>
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
/>
|
||||
</view>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
<!-- 编辑模式:mediaList 显示现有附件,newMediaList 显示新添加的附件 -->
|
||||
<block wx:else>
|
||||
<!-- 现有附件 -->
|
||||
<block wx:for="{{mediaList}}" wx:key="attachmentId">
|
||||
<view class="item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.thumbURL}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
></image>
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
<!-- 编辑模式:mediaList 显示现有附件,newMediaList 显示新添加的附件 -->
|
||||
<block wx:else>
|
||||
<!-- 现有附件 -->
|
||||
<block wx:for="{{mediaList}}" wx:key="attachmentId">
|
||||
<view class="item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.thumbURL}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
@@ -170,119 +161,135 @@
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
<image
|
||||
src="{{item.thumbURL}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
</view>
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
/>
|
||||
</view>
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{false}}"
|
||||
/>
|
||||
</view>
|
||||
</block>
|
||||
<!-- 新选择附件 -->
|
||||
<block wx:for="{{newMediaList}}" wx:key="index">
|
||||
<view class="item new-item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.path}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
</block>
|
||||
<!-- 新选择附件 -->
|
||||
<block wx:for="{{newMediaList}}" wx:key="index">
|
||||
<view class="item new-item">
|
||||
<!-- 图片 -->
|
||||
<image
|
||||
src="{{item.thumbPath}}"
|
||||
wx:if="{{item.type === mediaItemTypeEnum.IMAGE}}"
|
||||
src="{{item.path}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
<!-- 视频 -->
|
||||
<view wx:if="{{item.type === mediaItemTypeEnum.VIDEO}}" class="video-container">
|
||||
<image
|
||||
src="{{item.thumbPath}}"
|
||||
class="thumbnail"
|
||||
mode="aspectFill"
|
||||
bindtap="preview"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
></image>
|
||||
<t-icon class="play-icon" name="play" />
|
||||
</view>
|
||||
<!-- 新增标识 -->
|
||||
<t-icon class="new-badge" name="add" />
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteNewMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
/>
|
||||
</view>
|
||||
<!-- 新增标识 -->
|
||||
<t-icon class="new-badge" name="add" />
|
||||
<!-- 删除 -->
|
||||
<t-icon
|
||||
class="delete"
|
||||
name="close"
|
||||
bindtap="deleteNewMedia"
|
||||
data-index="{{index}}"
|
||||
data-new-media="{{true}}"
|
||||
/>
|
||||
</view>
|
||||
</block>
|
||||
</block>
|
||||
</block>
|
||||
<!-- 添加按钮 -->
|
||||
<t-button
|
||||
class="item add"
|
||||
theme="primary"
|
||||
plain="true"
|
||||
disabled="{{isSaving}}"
|
||||
bind:tap="addMedia"
|
||||
>
|
||||
<t-icon name="add" />
|
||||
</t-button>
|
||||
</view>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<!-- 添加按钮 -->
|
||||
<t-button
|
||||
class="item add"
|
||||
theme="primary"
|
||||
plain="true"
|
||||
disabled="{{isSaving}}"
|
||||
bind:tap="addMedia"
|
||||
>
|
||||
<t-icon name="add" />
|
||||
</t-button>
|
||||
</view>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
|
||||
<!-- 上传进度提示 -->
|
||||
<view wx:if="{{isUploading}}" class="section upload">
|
||||
<t-loading theme="circular" size="32rpx" />
|
||||
<text class="text">{{uploadInfo}}</text>
|
||||
</view>
|
||||
<!-- 上传进度提示 -->
|
||||
<view wx:if="{{isUploading}}" class="section upload">
|
||||
<t-loading theme="circular" size="32rpx" />
|
||||
<text class="text">{{uploadInfo}}</text>
|
||||
</view>
|
||||
|
||||
<!-- 按钮 -->
|
||||
<view class="section action">
|
||||
<t-button
|
||||
wx:if="{{mode === 'edit'}}"
|
||||
class="delete"
|
||||
theme="danger"
|
||||
variant="outline"
|
||||
size="large"
|
||||
bind:tap="deleteLocation"
|
||||
disabled="{{isSaving || isUploading}}"
|
||||
>
|
||||
删除
|
||||
</t-button>
|
||||
<t-button
|
||||
class="submit"
|
||||
theme="primary"
|
||||
size="large"
|
||||
bind:tap="submit"
|
||||
loading="{{isSaving}}"
|
||||
disabled="{{isSaving || isUploading}}"
|
||||
>
|
||||
{{mode === 'create' ? '创建地点' : '保存修改'}}
|
||||
</t-button>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 删除确认对话框 -->
|
||||
<t-dialog
|
||||
visible="{{deleteDialogVisible}}"
|
||||
title="删除地点"
|
||||
confirm-btn="{{ {content: '删除', variant: 'text', theme: 'danger'} }}"
|
||||
cancel-btn="取消"
|
||||
bind:confirm="confirmDelete"
|
||||
bind:cancel="cancelDelete"
|
||||
>
|
||||
<view slot="content" class="delete-dialog">
|
||||
<view class="tips">
|
||||
<text>此地点的图片和视频也会同步删除,删除后无法恢复,请输入 "</text>
|
||||
<text style="color: var(--theme-error)">确认删除</text>
|
||||
<text>" 以继续</text>
|
||||
<!-- 按钮 -->
|
||||
<view class="section action">
|
||||
<t-button
|
||||
wx:if="{{mode === 'edit'}}"
|
||||
class="delete"
|
||||
theme="danger"
|
||||
variant="outline"
|
||||
size="large"
|
||||
bind:tap="deleteLocation"
|
||||
disabled="{{isSaving || isUploading}}"
|
||||
>
|
||||
删除
|
||||
</t-button>
|
||||
<t-button
|
||||
class="submit"
|
||||
theme="primary"
|
||||
size="large"
|
||||
bind:tap="submit"
|
||||
loading="{{isSaving}}"
|
||||
disabled="{{isSaving || isUploading}}"
|
||||
>
|
||||
{{mode === 'create' ? '创建地点' : '保存修改'}}
|
||||
</t-button>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
<t-input placeholder="请输入:确认删除" model:value="{{deleteConfirmText}}" />
|
||||
</scroll-view>
|
||||
|
||||
<!-- 删除确认对话框 -->
|
||||
<t-dialog
|
||||
visible="{{deleteDialogVisible}}"
|
||||
title="删除地点"
|
||||
confirm-btn="{{ {content: '删除', variant: 'text', theme: 'danger'} }}"
|
||||
cancel-btn="取消"
|
||||
bind:confirm="confirmDelete"
|
||||
bind:cancel="cancelDelete"
|
||||
>
|
||||
<view slot="content" class="delete-dialog">
|
||||
<view class="tips">
|
||||
<text>此地点的图片和视频也会同步删除,删除后无法恢复,请输入 "</text>
|
||||
<text style="color: var(--theme-error)">确认删除</text>
|
||||
<text>" 以继续</text>
|
||||
</view>
|
||||
<t-input placeholder="请输入:确认删除" model:value="{{deleteConfirmText}}" />
|
||||
</view>
|
||||
</t-dialog>
|
||||
</block>
|
||||
<block wx:elif="{{permissionChecked}}">
|
||||
<view class="no-permission">
|
||||
<t-empty icon="error-circle" description="无权限操作" />
|
||||
</view>
|
||||
</t-dialog>
|
||||
</block>
|
||||
|
||||
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