feat: 初始化工程

This commit is contained in:
2026-09-06 16:07:53 +08:00
commit 423e8a3a2f
136 changed files with 34546 additions and 0 deletions

100
src/store/record.ts Normal file
View File

@@ -0,0 +1,100 @@
import { defineStore } from 'pinia'
import type { IRecord, IRecordForm } from "@/types/family";
import type {UploadFile} from "@wot-ui/ui/components/wd-upload/types";
export const useRecordStore = defineStore('record', {
state: () => ({
baseUrl: 'https://cxx0822.s.3q.hair',
recordList: [] as IRecord[],
recordForm: {
user_id: 0,
content: '',
image_list: [],
video_list: []
} as IRecordForm,
currentRecordId: 0,
showRecordPopup: false,
recordApiType: 'ADD' as 'ADD' | 'UPDATE',
imageFileList: [] as UploadFile[],
videoFileList: [] as UploadFile[],
}),
actions: {
async handleRecordApi() {
if (this.recordApiType === 'ADD') {
await this.addRecordApi()
} else if (this.recordApiType === 'UPDATE') {
await this.updateRecordApi()
}
await this.refreshRecord()
},
async refreshRecord() {
this.recordList = await this.getRecordListApi()
},
getEmptyForm(): IRecordForm {
return {
user_id: 0,
content: '',
image_list: [],
video_list: []
}
},
async getRecordListApi() {
return new Promise((resolve, reject) => {
wx.request({
url: `${this.baseUrl}/family-api/records`,
method: 'GET',
header: { 'Content-Type': 'application/json' },
data: {
skip: 0,
limit: 20
},
success: (res) => {
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(res.data)
} else {
reject({ status: res.statusCode, data: res.data })
}
},
fail: (err) => reject(err),
})
})
},
async addRecordApi() {
return new Promise((resolve, reject) => {
wx.request({
url: `${this.baseUrl}/family-api/records`,
method: 'POST',
header: { 'Content-Type': 'application/json' },
data: this.recordForm,
success: (res) => {
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(res.data)
} else {
reject({ status: res.statusCode, data: res.data })
}
},
fail: (err) => reject(err),
})
})
},
async updateRecordApi() {
return new Promise((resolve, reject) => {
wx.request({
url: `${this.baseUrl}/family-api/records/${this.currentRecordId}`,
method: 'PUT',
header: { 'Content-Type': 'application/json' },
data: this.recordForm,
success: (res) => {
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(res.data)
} else {
reject({ status: res.statusCode, data: res.data })
}
},
fail: (err) => reject(err),
})
})
}
},
})