|
|
@@ -41,10 +41,15 @@
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import { ref, onMounted, nextTick, computed } from 'vue'
|
|
|
+import { onLoad } from '@dcloudio/uni-app'
|
|
|
import CustomNav from '@/components/custom-nav.vue'
|
|
|
import { createNews, updateNews, uploadNewsImage, getNewsById } from '@/api/news'
|
|
|
|
|
|
-const query: Record<string, string> = (((globalThis as any).getCurrentPages ? (globalThis as any).getCurrentPages().slice(-1)[0]?.options : {}) as Record<string, string>) || {}
|
|
|
+const query = ref<Record<string, string>>({})
|
|
|
+
|
|
|
+onLoad((options) => {
|
|
|
+ query.value = options || {}
|
|
|
+})
|
|
|
|
|
|
const title = ref('')
|
|
|
const summary = ref('')
|
|
|
@@ -175,15 +180,15 @@ const save = async () => {
|
|
|
if (saving.value) return
|
|
|
saving.value = true
|
|
|
try {
|
|
|
- if (query.id) {
|
|
|
+ if (query.value.id) {
|
|
|
// 编辑
|
|
|
const payload = {
|
|
|
- id: query.id,
|
|
|
+ id: query.value.id,
|
|
|
title: title.value,
|
|
|
content: content.value,
|
|
|
summary: summary.value
|
|
|
}
|
|
|
- const res: any = await updateNews(query.id, payload)
|
|
|
+ const res: any = await updateNews(query.value.id, payload)
|
|
|
const r = res?.data ?? res
|
|
|
if (r && r.code === 200) {
|
|
|
uni.showToast({ title: '更新成功', icon: 'success' })
|
|
|
@@ -221,8 +226,9 @@ const cancel = () => {
|
|
|
|
|
|
onMounted(async () => {
|
|
|
// 如果是编辑,读取 id 并可调用接口拉取详情(这里模拟)
|
|
|
- const id = query.id || ''
|
|
|
+ const id = query.value.id || ''
|
|
|
if (id) {
|
|
|
+ console.log('Detected id:', id)
|
|
|
// 编辑:使用接口拉取真实数据
|
|
|
try {
|
|
|
const resp: any = await getNewsById(id)
|