Xiao_123 1 месяц назад
Родитель
Сommit
31f8d627fd
1 измененных файлов с 26 добавлено и 1 удалено
  1. 26 1
      pages/drawLots/fortune.vue

+ 26 - 1
pages/drawLots/fortune.vue

@@ -92,7 +92,7 @@
 
 <script setup>
 import { ref } from 'vue'
-import { onLoad } from '@dcloudio/uni-app'
+import { onLoad, onUnload } from '@dcloudio/uni-app'
 import { getDrawLots, getCalendarRecord, saveCalendarRecord } from '@/api/drawLots.js'
 
 const colorDict = {
@@ -153,6 +153,31 @@ onLoad((options) => {
   getCalendarData(options?.date.slice(0, 7))
 })
 
+const handleSaveAlmanac = async () => {
+	if (journal.value.almanac) return
+	const index = calendarRecord.value.findIndex(item => item.date === date.value)
+	if (index === -1) {
+		calendarRecord.value.push({
+			date: date.value,
+			almanac: almanac.value,
+			notes: '',
+			events: []
+		})
+	} else calendarRecord.value[index].almanac = almanac.value
+
+	await saveCalendarRecord({
+		openid: userInfo.value.openid,
+		month_key: date.value.slice(0, 7),
+		calendar_content: calendarRecord.value
+	})
+}
+
+onUnload(async () => {
+	console.log('onUnload')
+	// 没有编辑手账时,只查看黄历的需要在返回上一页时保存黄历信息
+	await handleSaveAlmanac()
+})
+
 const handleUpdateJournal = () => {
   isEdit.value = true
   inputType.value = 'textarea'