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

12
src/store/app.ts Normal file
View File

@@ -0,0 +1,12 @@
import { defineStore } from 'pinia'
export const useAppStore = defineStore('app', {
state: () => ({
version: '1.0.0.20260905',
baseUrl: 'https://cxx0822.s.3q.hair',
showFab: true,
}),
actions: {
},
})

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),
})
})
}
},
})

69
src/store/user.ts Normal file
View File

@@ -0,0 +1,69 @@
import { defineStore } from 'pinia'
import type { IUser } from "@/types/family";
import type { UploadFile } from "@wot-ui/ui/components/wd-upload/types";
export const useUserStore = defineStore('user', {
state: () => ({
baseUrl: 'https://cxx0822.s.3q.hair',
showUserPopup: false,
userForm: {
id: 0,
name: '',
avatar: '',
create_time: '',
update_time: '',
} as IUser,
imageFileList: [] as UploadFile[],
currentUser: {} as IUser,
userApiType: 'ADD' as 'ADD' | 'UPDATE',
isRefresh: false,
}),
actions: {
async handleUserApi() {
if (this.userApiType === 'ADD') {
this.currentUser = await this.addUserApi()
} else if (this.userApiType === 'UPDATE') {
this.currentUser = await this.updateUserApi()
}
wx.setStorageSync('USER', this.currentUser)
this.isRefresh = !this.isRefresh
},
async addUserApi() {
return new Promise((resolve, reject) => {
wx.request({
url: `${this.baseUrl}/family-api/users`,
method: 'POST',
header: { 'Content-Type': 'application/json' },
data: this.userForm,
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 updateUserApi() {
return new Promise((resolve, reject) => {
wx.request({
url: `${this.baseUrl}/family-api/users/${this.currentUser.id}`,
method: 'PUT',
header: { 'Content-Type': 'application/json' },
data: this.userForm,
success: (res) => {
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(res.data)
} else {
reject({ status: res.statusCode, data: res.data })
}
},
fail: (err) => reject(err),
})
})
}
},
})