open Location in journal-map

This commit is contained in:
Timi
2025-12-11 01:05:02 +08:00
parent 861ae8baff
commit 0379a1d3b5
6 changed files with 24 additions and 32 deletions

View File

@ -22,38 +22,23 @@ interface JournalDetailPanelData {
Component({ Component({
properties: { properties: {
// 是否显示
visible: { visible: {
type: Boolean, type: Boolean,
value: false value: false
}, },
// 标题(如 "2024 年 1 月 1 日" 或位置名称)
title: { title: {
type: String, type: String,
value: "" value: ""
}, },
// 日记列表
journals: { journals: {
type: Array, type: Array,
value: [] value: []
}, },
// 是否显示标题位置图标 mode: {
showLocationIcon: { type: String,
type: Boolean, value: "DATE"
value: false
},
// 是否显示每条日记的日期
showJournalDate: {
type: Boolean,
value: true
},
// 是否显示每条日记的位置
showJournalLocation: {
type: Boolean,
value: true
} }
}, },
data: <JournalDetailPanelData>{ data: <JournalDetailPanelData>{
currentJournalIndex: 0, currentJournalIndex: 0,
}, },
@ -72,20 +57,21 @@ Component({
methods: { methods: {
/** 关闭详情 */ /** 关闭详情 */
closeDetail() { closeDetail() {
this.triggerEvent('close'); this.triggerEvent("close");
}, },
/** swiper 切换事件 */ /** swiper 切换事件 */
onSwiperChange(e: WechatMiniprogram.SwiperChange) { onSwiperChange(e: WechatMiniprogram.SwiperChange) {
this.setData({ this.setData({
currentJournalIndex: e.detail.current currentJournalIndex: e.detail.current
}); });
}, },
openLocation(e: WechatMiniprogram.BaseEvent) { openLocation(e: WechatMiniprogram.BaseEvent) {
const { journalIndex } = e.currentTarget.dataset; const { journalIndex } = e.currentTarget.dataset;
if (!journalIndex && this.properties.mode !== "LOCATION") {
return;
}
const journals = this.properties.journals as JournalInfo[]; const journals = this.properties.journals as JournalInfo[];
const journal = journals[journalIndex]; const journal = journals[journalIndex || 0];
if (journal.lat && journal.lng) { if (journal.lat && journal.lng) {
wx.openLocation({ wx.openLocation({
latitude: journal.lat, latitude: journal.lat,

View File

@ -9,8 +9,8 @@
<view class="detail-content"> <view class="detail-content">
<view class="header"> <view class="header">
<view class="info"> <view class="info">
<view wx:if="{{title}}" class="title"> <view wx:if="{{title}}" class="title" catchtap="openLocation">
<t-icon wx:if="{{showLocationIcon}}" class="icon" name="location-filled" /> <t-icon wx:if="{{mode === 'LOCATION'}}" class="icon" name="location-filled" />
<text>{{title}}</text> <text>{{title}}</text>
</view> </view>
</view> </view>
@ -27,7 +27,7 @@
<view class="journal-item"> <view class="journal-item">
<view class="journal-header"> <view class="journal-header">
<view <view
wx:if="{{item.location && showJournalLocation}}" wx:if="{{item.location && mode === 'DATE'}}"
class="location" class="location"
catchtap="openLocation" catchtap="openLocation"
data-journal-index="{{currentJournalIndex}}" data-journal-index="{{currentJournalIndex}}"
@ -35,7 +35,7 @@
<t-icon class="icon" name="location-filled" /> <t-icon class="icon" name="location-filled" />
<text class="text">{{item.location}}</text> <text class="text">{{item.location}}</text>
</view> </view>
<view wx:if="{{showJournalDate}}" class="date">{{item.date}}</view> <view wx:if="{{mode === 'LOCATION'}}" class="date">{{item.date}}</view>
</view> </view>
<view wx:if="{{item.idea}}" class="idea">{{item.idea}}</view> <view wx:if="{{item.idea}}" class="idea">{{item.idea}}</view>
<scroll-view wx:if="{{item.items && item.items.length > 0}}" scroll-y class="items-scroll"> <scroll-view wx:if="{{item.items && item.items.length > 0}}" scroll-y class="items-scroll">

View File

@ -13,7 +13,6 @@
visible="{{popupVisible}}" visible="{{popupVisible}}"
title="{{selectedDate.displayDate}}" title="{{selectedDate.displayDate}}"
journals="{{selectedDate.journals}}" journals="{{selectedDate.journals}}"
show-journal-date="{{false}}" mode="DATE"
show-journal-location="{{true}}"
bind:close="closeDetail" bind:close="closeDetail"
/> />

View File

@ -2,7 +2,7 @@
import config from "../../../config/index"; import config from "../../../config/index";
import Time from "../../../utils/Time"; import Time from "../../../utils/Time";
import { Journal, JournalPageType } from "../../../types/Journal"; import { Journal, JournalPageType } from "../../../types/Journal";
import { MediaAttachExt, MediaAttachType } from "../../../types/Attachment"; import { MediaAttachType } from "../../../types/Attachment";
import Toolkit from "../../../utils/Toolkit"; import Toolkit from "../../../utils/Toolkit";
interface MapMarker { interface MapMarker {
@ -239,6 +239,8 @@ Page({
id: journal.id, id: journal.id,
date: Time.toPassedDateTime(journal.createdAt), date: Time.toPassedDateTime(journal.createdAt),
time: `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`, time: `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`,
lat: journal.lat,
lng: journal.lng,
location: journal.location, location: journal.location,
idea: journal.idea, idea: journal.idea,
items: journal.items items: journal.items

View File

@ -41,8 +41,6 @@
visible="{{showDetail && detailVisible}}" visible="{{showDetail && detailVisible}}"
title="{{selectedLocation.location}}" title="{{selectedLocation.location}}"
journals="{{selectedLocation.journals}}" journals="{{selectedLocation.journals}}"
show-location-icon="{{true}}" mode="LOCATION"
show-journal-date="{{true}}"
show-journal-location="{{false}}"
bind:close="closeDetail" bind:close="closeDetail"
/> />

View File

@ -62,3 +62,10 @@ export type Location = {
/** 描述 */ /** 描述 */
text?: string; text?: string;
} }
export enum JournalDetailType {
DATE = "DATE",
LOCATION = "LOCATION"
}