refactor travel
This commit is contained in:
16
miniprogram/pages/main/travel-location-editor/index.json
Normal file
16
miniprogram/pages/main/travel-location-editor/index.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-cell": "tdesign-miniprogram/cell/cell",
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-rate": "tdesign-miniprogram/rate/rate",
|
||||
"t-input": "tdesign-miniprogram/input/input",
|
||||
"t-button": "tdesign-miniprogram/button/button",
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"t-loading": "tdesign-miniprogram/loading/loading",
|
||||
"t-stepper": "tdesign-miniprogram/stepper/stepper",
|
||||
"t-textarea": "tdesign-miniprogram/textarea/textarea",
|
||||
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group"
|
||||
},
|
||||
"styleIsolation": "shared"
|
||||
}
|
||||
226
miniprogram/pages/main/travel-location-editor/index.less
Normal file
226
miniprogram/pages/main/travel-location-editor/index.less
Normal file
@ -0,0 +1,226 @@
|
||||
// pages/main/travel-location-editor/index.less
|
||||
|
||||
.container {
|
||||
width: 100vw;
|
||||
min-height: 100vh;
|
||||
background: var(--theme-bg-secondary);
|
||||
|
||||
.content {
|
||||
padding-bottom: 64rpx;
|
||||
|
||||
.loading {
|
||||
display: flex;
|
||||
padding: 128rpx 0;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
|
||||
.loading-text {
|
||||
color: var(--theme-text-secondary);
|
||||
margin-top: 24rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-top: 48rpx;
|
||||
|
||||
.picker .slot {
|
||||
gap: 16rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.location-slot {
|
||||
gap: 16rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.location-text {
|
||||
color: var(--theme-text-primary);
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.location-placeholder {
|
||||
color: var(--theme-text-placeholder);
|
||||
font-size: 28rpx;
|
||||
}
|
||||
}
|
||||
|
||||
&.media {
|
||||
|
||||
.gallery {
|
||||
gap: 10rpx;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
|
||||
.item {
|
||||
width: 240rpx;
|
||||
height: 240rpx;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
background: var(--theme-bg-card);
|
||||
box-shadow: 1px 1px 6px var(--theme-shadow-light);
|
||||
border-radius: 2rpx;
|
||||
|
||||
&.add {
|
||||
color: var(--theme-wx);
|
||||
margin: 0;
|
||||
font-size: 80rpx;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.thumbnail {
|
||||
width: 240rpx;
|
||||
height: 240rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.video-container {
|
||||
position: relative;
|
||||
|
||||
|
||||
.play-icon {
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
color: rgba(255, 255, 255, .8);
|
||||
z-index: 2;
|
||||
position: absolute;
|
||||
font-size: 128rpx;
|
||||
transform: translate(-50%, -50%);
|
||||
text-shadow: 4rpx 4rpx 0 rgba(0, 0, 0, .5);
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.delete {
|
||||
top: 10rpx;
|
||||
right: 10rpx;
|
||||
color: rgba(255, 255, 255, .6);
|
||||
z-index: 3;
|
||||
position: absolute;
|
||||
font-size: 45rpx;
|
||||
|
||||
&::after {
|
||||
content: "";
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: -1;
|
||||
position: absolute;
|
||||
background: rgba(0, 0, 0, .6);
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
.new-badge {
|
||||
top: 10rpx;
|
||||
left: 10rpx;
|
||||
color: var(--theme-wx);
|
||||
z-index: 3;
|
||||
display: flex;
|
||||
position: absolute;
|
||||
font-size: 45rpx;
|
||||
text-shadow: 4rpx 4rpx 0 rgba(0, 0, 0, .5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.media-section {
|
||||
margin-top: 48rpx;
|
||||
padding: 32rpx;
|
||||
background: var(--theme-bg-card);
|
||||
|
||||
.section-title {
|
||||
color: var(--theme-text-primary);
|
||||
margin-bottom: 24rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.media-grid {
|
||||
gap: 24rpx;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
|
||||
.media-item {
|
||||
width: 100%;
|
||||
height: 200rpx;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
border-radius: 12rpx;
|
||||
|
||||
.media-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.video-badge {
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
display: flex;
|
||||
position: absolute;
|
||||
transform: translate(-50%, -50%);
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.media-delete {
|
||||
top: 8rpx;
|
||||
right: 8rpx;
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
display: flex;
|
||||
position: absolute;
|
||||
background: rgba(0, 0, 0, .5);
|
||||
align-items: center;
|
||||
border-radius: 50%;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
.media-add {
|
||||
width: 100%;
|
||||
height: 200rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-radius: 12rpx;
|
||||
justify-content: center;
|
||||
background: var(--theme-bg-page);
|
||||
border: 2rpx dashed var(--theme-border);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.upload-info {
|
||||
gap: 16rpx;
|
||||
display: flex;
|
||||
padding: 24rpx 32rpx;
|
||||
margin-top: 24rpx;
|
||||
align-items: center;
|
||||
border-radius: 12rpx;
|
||||
background: var(--theme-bg-card);
|
||||
|
||||
.upload-text {
|
||||
color: var(--theme-text-secondary);
|
||||
font-size: 28rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.submit-section {
|
||||
gap: 24rpx;
|
||||
display: flex;
|
||||
padding: 24rpx 16rpx 48rpx 16rpx;
|
||||
margin-top: 64rpx;
|
||||
|
||||
.delete-btn {
|
||||
flex: .6;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
501
miniprogram/pages/main/travel-location-editor/index.ts
Normal file
501
miniprogram/pages/main/travel-location-editor/index.ts
Normal file
@ -0,0 +1,501 @@
|
||||
// pages/main/travel-location-editor/index.ts
|
||||
|
||||
import { Network, WechatMediaItem } from "../../../utils/Network";
|
||||
import { TravelLocationApi } from "../../../api/TravelLocationApi";
|
||||
import { TravelLocationType } from "../../../types/Travel";
|
||||
import { MediaAttachExt, MediaAttachType } from "../../../types/Attachment";
|
||||
import config from "../../../config/index";
|
||||
import { MediaItem, MediaItemType } from "../../../types/UI";
|
||||
|
||||
interface TravelLocationEditorData {
|
||||
/** 模式:create 或 edit */
|
||||
mode: "create" | "edit";
|
||||
/** 旅行地点 ID(编辑模式) */
|
||||
id?: number;
|
||||
/** 关联的旅行计划 ID */
|
||||
travelId: number;
|
||||
/** 地点类型 */
|
||||
type: TravelLocationType;
|
||||
/** 标题 */
|
||||
title: string;
|
||||
/** 说明 */
|
||||
description: string;
|
||||
/** 位置描述 */
|
||||
location: string;
|
||||
/** 纬度 */
|
||||
lat: number;
|
||||
/** 经度 */
|
||||
lng: number;
|
||||
/** 费用 */
|
||||
amount: number;
|
||||
/** 是否需要身份证 */
|
||||
requireIdCard: boolean;
|
||||
/** 必要评分 */
|
||||
score: number;
|
||||
/** 媒体列表(创建和编辑模式使用) */
|
||||
mediaList: (MediaItem | WechatMediaItem)[];
|
||||
/** 新媒体列表(编辑模式使用) */
|
||||
newMediaList: WechatMediaItem[];
|
||||
/** 是否正在加载(编辑模式) */
|
||||
isLoading: boolean;
|
||||
/** 是否正在保存 */
|
||||
isSaving: boolean;
|
||||
/** 是否正在上传 */
|
||||
isUploading: boolean;
|
||||
/** 上传进度信息 */
|
||||
uploadInfo: string;
|
||||
/** 地点类型选项 */
|
||||
locationTypes: { label: string; value: TravelLocationType }[];
|
||||
/** 地点类型选中索引 */
|
||||
locationTypeIndex: number;
|
||||
/** 媒体类型枚举 */
|
||||
mediaItemTypeEnum: any;
|
||||
}
|
||||
|
||||
Page({
|
||||
data: <TravelLocationEditorData>{
|
||||
mode: "create",
|
||||
id: undefined,
|
||||
travelId: 0,
|
||||
type: TravelLocationType.ATTRACTION,
|
||||
title: "",
|
||||
description: "",
|
||||
location: "",
|
||||
lat: 0,
|
||||
lng: 0,
|
||||
amount: 0,
|
||||
requireIdCard: false,
|
||||
score: 3,
|
||||
mediaList: [],
|
||||
newMediaList: [],
|
||||
isLoading: false,
|
||||
isSaving: false,
|
||||
isUploading: false,
|
||||
uploadInfo: "",
|
||||
mediaItemTypeEnum: {
|
||||
...MediaItemType
|
||||
},
|
||||
locationTypes: [
|
||||
{ label: "景点", value: TravelLocationType.ATTRACTION },
|
||||
{ label: "酒店", value: TravelLocationType.HOTEL },
|
||||
{ label: "餐厅", value: TravelLocationType.RESTAURANT },
|
||||
{ label: "交通站点", value: TravelLocationType.TRANSPORT },
|
||||
{ label: "购物", value: TravelLocationType.SHOPPING },
|
||||
{ label: "其他", value: TravelLocationType.OTHER }
|
||||
],
|
||||
locationTypeIndex: 0
|
||||
},
|
||||
|
||||
onLoad(options: any) {
|
||||
// 获取 travelId(必填)
|
||||
const travelId = options.travelId ? parseInt(options.travelId) : 0;
|
||||
if (!travelId) {
|
||||
wx.showToast({
|
||||
title: "缺少旅行计划 ID",
|
||||
icon: "error"
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
|
||||
// 判断模式:有 ID 是编辑,无 ID 是创建
|
||||
const id = options.id ? parseInt(options.id) : undefined;
|
||||
|
||||
if (id) {
|
||||
// 编辑模式
|
||||
this.setData({
|
||||
mode: "edit",
|
||||
id,
|
||||
travelId,
|
||||
isLoading: true
|
||||
});
|
||||
this.loadLocationDetail(id);
|
||||
} else {
|
||||
// 创建模式
|
||||
this.setData({
|
||||
mode: "create",
|
||||
travelId,
|
||||
isLoading: false
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/** 加载地点详情(编辑模式) */
|
||||
async loadLocationDetail(id: number) {
|
||||
wx.showLoading({ title: "加载中...", mask: true });
|
||||
|
||||
try {
|
||||
const location = await TravelLocationApi.getDetail(id);
|
||||
|
||||
// 计算地点类型索引
|
||||
const type = location.type || TravelLocationType.ATTRACTION;
|
||||
const locationTypeIndex = this.data.locationTypes.findIndex(
|
||||
item => item.value === type
|
||||
);
|
||||
|
||||
const items = location.items || [];
|
||||
const thumbItems = items.filter((item) => item.attachType === MediaAttachType.THUMB);
|
||||
|
||||
const mediaList: MediaItem[] = thumbItems.map((thumbItem) => {
|
||||
const ext = thumbItem.ext = JSON.parse(thumbItem.ext!.toString()) as MediaAttachExt;
|
||||
const thumbURL = `${config.url}/attachment/read/${thumbItem.mongoId}`;
|
||||
const sourceURL = `${config.url}/attachment/read/${ext.sourceMongoId}`;
|
||||
return {
|
||||
type: ext.isVideo ? MediaItemType.VIDEO : MediaItemType.IMAGE,
|
||||
thumbURL,
|
||||
sourceURL,
|
||||
size: thumbItem.size || 0,
|
||||
attachmentId: thumbItem.id
|
||||
} as MediaItem;
|
||||
});
|
||||
|
||||
this.setData({
|
||||
type,
|
||||
locationTypeIndex: locationTypeIndex >= 0 ? locationTypeIndex : 0,
|
||||
title: location.title || "",
|
||||
description: location.description || "",
|
||||
location: location.location || "",
|
||||
lat: location.lat || 0,
|
||||
lng: location.lng || 0,
|
||||
amount: location.amount || 0,
|
||||
requireIdCard: location.requireIdCard || false,
|
||||
score: location.score !== undefined ? location.score : 3,
|
||||
mediaList,
|
||||
isLoading: false
|
||||
});
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: "加载失败",
|
||||
icon: "error"
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1500);
|
||||
} finally {
|
||||
wx.hideLoading();
|
||||
}
|
||||
},
|
||||
|
||||
/** 改变地点类型 */
|
||||
onChangeLocationType(e: any) {
|
||||
const index = e.detail.value;
|
||||
this.setData({
|
||||
locationTypeIndex: index,
|
||||
type: this.data.locationTypes[index].value
|
||||
});
|
||||
},
|
||||
|
||||
/** 改变是否需要身份证 */
|
||||
onChangeRequireIdCard(e: any) {
|
||||
this.setData({ requireIdCard: e.detail.value });
|
||||
},
|
||||
|
||||
/** 改变评分 */
|
||||
onChangeScore(e: any) {
|
||||
this.setData({ score: e.detail.value });
|
||||
},
|
||||
|
||||
/** 选择位置 */
|
||||
chooseLocation() {
|
||||
wx.chooseLocation({
|
||||
success: (res) => {
|
||||
const locationName = res.address || res.name;
|
||||
const updateData: any = {
|
||||
location: locationName,
|
||||
lat: res.latitude,
|
||||
lng: res.longitude
|
||||
};
|
||||
|
||||
// 如果标题为空,使用选择的地点名称作为标题
|
||||
if (!this.data.title.trim()) {
|
||||
updateData.title = res.name || locationName;
|
||||
}
|
||||
|
||||
this.setData(updateData);
|
||||
},
|
||||
fail: (err) => {
|
||||
if (err.errMsg.includes("auth deny")) {
|
||||
wx.showToast({
|
||||
title: "请授权位置权限",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/** 添加媒体 */
|
||||
addMedia() {
|
||||
const that = this;
|
||||
wx.chooseMedia({
|
||||
mediaType: ["mix"],
|
||||
sourceType: ["album", "camera"],
|
||||
camera: "back",
|
||||
success(res) {
|
||||
wx.showLoading({
|
||||
title: "加载中..",
|
||||
mask: true
|
||||
});
|
||||
const tempFiles = res.tempFiles;
|
||||
const newMedia = tempFiles.map(item => {
|
||||
return {
|
||||
type: (<any>MediaItemType)[item.fileType.toUpperCase()],
|
||||
path: item.tempFilePath,
|
||||
thumbPath: item.thumbTempFilePath,
|
||||
size: item.size,
|
||||
duration: item.duration,
|
||||
raw: item
|
||||
} as WechatMediaItem;
|
||||
});
|
||||
if (that.data.mode === "create") {
|
||||
that.setData({
|
||||
mediaList: [...that.data.mediaList, ...newMedia]
|
||||
});
|
||||
} else {
|
||||
that.setData({
|
||||
newMediaList: [...that.data.newMediaList, ...newMedia]
|
||||
});
|
||||
}
|
||||
wx.hideLoading();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/** 删除媒体(创建模式) */
|
||||
deleteMedia(e: any) {
|
||||
const { index } = e.currentTarget.dataset;
|
||||
const mediaList = this.data.mediaList;
|
||||
mediaList.splice(index, 1);
|
||||
this.setData({ mediaList });
|
||||
},
|
||||
|
||||
/** 删除新媒体(编辑模式) */
|
||||
deleteNewMedia(e: any) {
|
||||
const { index } = e.currentTarget.dataset;
|
||||
const newMediaList = this.data.newMediaList;
|
||||
newMediaList.splice(index, 1);
|
||||
this.setData({ newMediaList });
|
||||
},
|
||||
|
||||
/** 删除已有媒体(编辑模式) */
|
||||
deleteExistingMedia(e: any) {
|
||||
const { index } = e.currentTarget.dataset;
|
||||
const existingMedia = this.data.mediaList;
|
||||
existingMedia.splice(index, 1);
|
||||
this.setData({ existingMedia });
|
||||
},
|
||||
|
||||
/** 预览媒体 */
|
||||
preview(e: WechatMiniprogram.BaseEvent) {
|
||||
const isNewMedia = e.currentTarget.dataset.newMedia;
|
||||
const index = e.currentTarget.dataset.index;
|
||||
|
||||
if (this.data.mode === "create") {
|
||||
// 创建模式:只有 mediaList
|
||||
const sources = (this.data.mediaList as WechatMediaItem[]).map(item => ({
|
||||
url: item.path,
|
||||
type: MediaItemType[item.type].toLowerCase()
|
||||
}));
|
||||
|
||||
const total = sources.length;
|
||||
const startIndex = Math.max(0, index - 25);
|
||||
const endIndex = Math.min(total, startIndex + 50);
|
||||
const newCurrentIndex = index - startIndex;
|
||||
|
||||
wx.previewMedia({
|
||||
current: newCurrentIndex,
|
||||
sources: sources.slice(startIndex, endIndex) as WechatMiniprogram.MediaSource[]
|
||||
});
|
||||
} else {
|
||||
// 编辑模式:mediaList + newMediaList
|
||||
const sources = (this.data.mediaList as MediaItem[]).map(item => ({
|
||||
url: item.sourceURL,
|
||||
type: MediaItemType[item.type].toLowerCase()
|
||||
}));
|
||||
const newSources = this.data.newMediaList.map(item => ({
|
||||
url: item.path,
|
||||
type: MediaItemType[item.type].toLowerCase()
|
||||
}));
|
||||
const allSources = [...sources, ...newSources];
|
||||
const itemIndex = isNewMedia ? this.data.mediaList.length + index : index;
|
||||
const total = allSources.length;
|
||||
|
||||
const startIndex = Math.max(0, itemIndex - 25);
|
||||
const endIndex = Math.min(total, startIndex + 50);
|
||||
const newCurrentIndex = itemIndex - startIndex;
|
||||
|
||||
wx.previewMedia({
|
||||
current: newCurrentIndex,
|
||||
sources: allSources.slice(startIndex, endIndex) as WechatMiniprogram.MediaSource[]
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/** 取消 */
|
||||
cancel() {
|
||||
wx.navigateBack();
|
||||
},
|
||||
|
||||
/** 删除地点 */
|
||||
deleteLocation() {
|
||||
wx.showModal({
|
||||
title: "确认删除",
|
||||
content: "确定要删除这个地点吗?删除后无法恢复。",
|
||||
success: async (res) => {
|
||||
if (res.confirm && this.data.id) {
|
||||
try {
|
||||
await TravelLocationApi.delete(this.data.id);
|
||||
wx.showToast({
|
||||
title: "删除成功",
|
||||
icon: "success"
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: "删除失败",
|
||||
icon: "error"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/** 提交/保存 */
|
||||
submit() {
|
||||
// 验证必填字段
|
||||
if (!this.data.title.trim()) {
|
||||
wx.showToast({
|
||||
title: "请输入标题",
|
||||
icon: "error"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.data.location || !this.data.lat || !this.data.lng) {
|
||||
wx.showToast({
|
||||
title: "请选择位置",
|
||||
icon: "error"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.data.mode === "create") {
|
||||
this.createLocation();
|
||||
} else {
|
||||
this.updateLocation();
|
||||
}
|
||||
},
|
||||
|
||||
/** 创建地点 */
|
||||
async createLocation() {
|
||||
this.setData({ isSaving: true });
|
||||
|
||||
try {
|
||||
// 上传媒体文件
|
||||
this.setData({
|
||||
isUploading: true,
|
||||
uploadInfo: "正在上传 0%"
|
||||
});
|
||||
const tempFileIds = await Network.uploadFiles({
|
||||
mediaList: this.data.mediaList as WechatMediaItem[],
|
||||
onProgress: ({ percent }) => {
|
||||
this.setData({
|
||||
uploadInfo: `正在上传 ${percent}%`
|
||||
});
|
||||
}
|
||||
});
|
||||
this.setData({
|
||||
isUploading: false,
|
||||
uploadInfo: ""
|
||||
});
|
||||
|
||||
// 创建地点
|
||||
await TravelLocationApi.create({
|
||||
travelId: this.data.travelId,
|
||||
type: this.data.type,
|
||||
title: this.data.title.trim(),
|
||||
description: this.data.description.trim(),
|
||||
location: this.data.location,
|
||||
lat: this.data.lat,
|
||||
lng: this.data.lng,
|
||||
amount: this.data.amount,
|
||||
requireIdCard: this.data.requireIdCard,
|
||||
score: this.data.score,
|
||||
tempFileIds
|
||||
});
|
||||
wx.showToast({
|
||||
title: "创建成功",
|
||||
icon: "success"
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
isSaving: false,
|
||||
isUploading: false,
|
||||
uploadInfo: ""
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/** 更新地点 */
|
||||
async updateLocation() {
|
||||
this.setData({ isSaving: true });
|
||||
try {
|
||||
// 保留的附件 ID 列表
|
||||
const attachmentIds = (this.data.mediaList as MediaItem[]).map(item => item.attachmentId);
|
||||
// 上传新媒体文件
|
||||
this.setData({
|
||||
isUploading: true,
|
||||
uploadInfo: "正在上传 0%"
|
||||
});
|
||||
const tempFileIds = await Network.uploadFiles({
|
||||
mediaList: this.data.newMediaList,
|
||||
onProgress: ({ percent }) => {
|
||||
this.setData({
|
||||
uploadInfo: `正在上传 ${percent}%`
|
||||
});
|
||||
}
|
||||
});
|
||||
this.setData({
|
||||
isUploading: false,
|
||||
uploadInfo: ""
|
||||
});
|
||||
// 更新地点
|
||||
await TravelLocationApi.update({
|
||||
id: this.data.id!,
|
||||
travelId: this.data.travelId,
|
||||
type: this.data.type,
|
||||
title: this.data.title.trim(),
|
||||
description: this.data.description.trim(),
|
||||
location: this.data.location,
|
||||
lat: this.data.lat,
|
||||
lng: this.data.lng,
|
||||
amount: this.data.amount,
|
||||
requireIdCard: this.data.requireIdCard,
|
||||
score: this.data.score,
|
||||
attachmentIds,
|
||||
tempFileIds
|
||||
});
|
||||
wx.showToast({
|
||||
title: "保存成功",
|
||||
icon: "success"
|
||||
});
|
||||
setTimeout(() => {
|
||||
wx.navigateBack();
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
isSaving: false,
|
||||
isUploading: false,
|
||||
uploadInfo: ""
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
242
miniprogram/pages/main/travel-location-editor/index.wxml
Normal file
242
miniprogram/pages/main/travel-location-editor/index.wxml
Normal file
@ -0,0 +1,242 @@
|
||||
<!--pages/main/travel-location-editor/index.wxml-->
|
||||
<t-navbar title="{{mode === 'create' ? '添加地点' : '编辑地点'}}">
|
||||
<text slot="left" bindtap="cancel">取消</text>
|
||||
</t-navbar>
|
||||
|
||||
<scroll-view class="container" 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">
|
||||
<t-cell title="地点类型">
|
||||
<view slot="right-icon">
|
||||
<picker
|
||||
class="picker"
|
||||
mode="selector"
|
||||
range="{{locationTypes}}"
|
||||
range-key="label"
|
||||
value="{{locationTypeIndex}}"
|
||||
bindchange="onChangeLocationType"
|
||||
>
|
||||
<view class="slot">
|
||||
<text>{{locationTypes[locationTypeIndex].label}}</text>
|
||||
<t-icon name="chevron-right" size="20px" class="icon" />
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
</t-cell>
|
||||
<t-cell title="位置" required bind:click="chooseLocation">
|
||||
<view slot="right-icon">
|
||||
<view class="location-slot">
|
||||
<text wx:if="{{location}}" class="location-text">{{location}}</text>
|
||||
<text wx:else class="location-placeholder">点击选择位置</text>
|
||||
<t-icon name="chevron-right" size="20px" class="icon" />
|
||||
</view>
|
||||
</view>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-cell-group class="section">
|
||||
<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">
|
||||
<t-input
|
||||
model:value="{{amount}}"
|
||||
placeholder="0"
|
||||
label="费用"
|
||||
suffix="元"
|
||||
align="right"
|
||||
/>
|
||||
<t-cell title="必要评分">
|
||||
<view slot="right-icon">
|
||||
<t-rate
|
||||
value="{{score}}"
|
||||
count="{{5}}"
|
||||
size="24px"
|
||||
bind:change="onChangeScore"
|
||||
/>
|
||||
</view>
|
||||
</t-cell>
|
||||
<t-cell title="需要身份证">
|
||||
<view slot="right-icon">
|
||||
<switch checked="{{requireIdCard}}" bindchange="onChangeRequireIdCard" />
|
||||
</view>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<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">
|
||||
<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>
|
||||
</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">
|
||||
<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>
|
||||
</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">
|
||||
<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>
|
||||
</block>
|
||||
</block>
|
||||
<!-- 添加按钮 -->
|
||||
<t-button
|
||||
class="item add"
|
||||
theme="primary"
|
||||
plain="true"
|
||||
disabled="{{isSaving}}"
|
||||
bind:tap="addMedia"
|
||||
>
|
||||
<t-icon name="add" />
|
||||
</t-button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 上传进度提示 -->
|
||||
<view wx:if="{{isUploading}}" class="upload-info">
|
||||
<t-loading theme="circular" size="32rpx" />
|
||||
<text class="upload-text">{{uploadInfo}}</text>
|
||||
</view>
|
||||
|
||||
<!-- 按钮 -->
|
||||
<view class="submit-section">
|
||||
<t-button
|
||||
wx:if="{{mode === 'edit'}}"
|
||||
class="delete-btn"
|
||||
theme="danger"
|
||||
variant="outline"
|
||||
size="large"
|
||||
bind:tap="deleteLocation"
|
||||
disabled="{{isSaving || isUploading}}"
|
||||
>
|
||||
删除
|
||||
</t-button>
|
||||
<t-button
|
||||
class="submit-btn"
|
||||
theme="primary"
|
||||
size="large"
|
||||
bind:tap="submit"
|
||||
loading="{{isSaving}}"
|
||||
disabled="{{isSaving || isUploading}}"
|
||||
>
|
||||
{{mode === 'create' ? '创建地点' : '保存修改'}}
|
||||
</t-button>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</scroll-view>
|
||||
Reference in New Issue
Block a user