From 8dce0346a744ad4fac19a627812298550582f9a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=96=87=E5=B3=B0?= Date: Fri, 17 Apr 2026 20:46:21 +0800 Subject: [PATCH] =?UTF-8?q?up=20Signed-off-by:=20=E5=90=B4=E6=96=87?= =?UTF-8?q?=E5=B3=B0=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/index.js | 39 +++--- api/request.js | 48 +------ api/user.js | 9 ++ components/my-toast/my-toast.vue | 74 +++++++++++ pages.json | 5 +- pages/login/login.vue | 40 +++++- pages/settings/settings.vue | 206 +++++++++++++++++++++++++++++-- pages/user/user.vue | 1 + stores/config.js | 13 +- utils/index.js | 13 ++ 10 files changed, 370 insertions(+), 78 deletions(-) create mode 100644 api/user.js create mode 100644 components/my-toast/my-toast.vue create mode 100644 utils/index.js diff --git a/api/index.js b/api/index.js index b983a61..e8bab20 100644 --- a/api/index.js +++ b/api/index.js @@ -4,21 +4,28 @@ */ // 用户相关 -export const user = { - login: (data) => post('/api/user/login', data), - logout: () => post('/api/user/logout'), - info: () => get('/api/user/info') + +export const api = { + /** + * GET 请求(一般不需要认证) + */ + get(path) { + + }, + + /** + * POST JSON + */ + post(path, data = {},callback) { + console.log("post") + }, + + /** + * POST FormData(文件上传) + */ + upload(path, file) { + + }, } -// 订单相关 -export const order = { - list: (data) => get('/api/order/list', data), - detail: (id) => get('/api/order/detail', { id }), - create: (data) => post('/api/order/create', data) -} - -// 消息相关 -export const message = { - list: (data) => get('/api/message/list', data), - read: (id) => post('/api/message/read', { id }) -} +export default api \ No newline at end of file diff --git a/api/request.js b/api/request.js index 26478bc..d21fd71 100644 --- a/api/request.js +++ b/api/request.js @@ -1,50 +1,4 @@ import { useConfigStore } from '@/stores/config' -/** - * 基础请求封装 - * @param {string} path - 接口路径 - * @param {object} data - 请求参数 - * @param {string} method - 请求方法 - */ -export const request = (path, data = {}, method = 'GET') => { - const config = useConfigStore() - - return new Promise((resolve, reject) => { - uni.request({ - url: config.apiBaseUrl + path, - data, - method, - header: { - 'Content-Type': 'application/json' - }, - success: (res) => { - if (res.statusCode === 200) { - resolve(res.data) - } else { - uni.showToast({ - title: '请求失败', - icon: 'none' - }) - reject(res) - } - }, - fail: (err) => { - uni.showToast({ - title: '网络错误', - icon: 'none' - }) - reject(err) - } - }) - }) -} +const useConfig=useConfigStore() -/** - * GET 请求 - */ -export const get = (path, data) => request(path, data, 'GET') - -/** - * POST 请求 - */ -export const post = (path, data) => request(path, data, 'POST') diff --git a/api/user.js b/api/user.js new file mode 100644 index 0000000..532c7f6 --- /dev/null +++ b/api/user.js @@ -0,0 +1,9 @@ +import api from "."; + +export const userApi = { + + login(username, password, remember) { + return api.post('/users/login', { username, password, remember }) + }, + +} \ No newline at end of file diff --git a/components/my-toast/my-toast.vue b/components/my-toast/my-toast.vue new file mode 100644 index 0000000..363ec9f --- /dev/null +++ b/components/my-toast/my-toast.vue @@ -0,0 +1,74 @@ + + + + + diff --git a/pages.json b/pages.json index 12069a8..988f9b9 100644 --- a/pages.json +++ b/pages.json @@ -41,7 +41,10 @@ "navigationBarTextStyle": "black", "navigationBarTitleText": "uni-app", "navigationBarBackgroundColor": "#F8F8F8", - "backgroundColor": "#F8F8F8" + "backgroundColor": "#F8F8F8", + "usingComponents": { + "my-toast": "/components/my-toast/my-toast" + } }, "tabBar": { "color": "#7A7E83", diff --git a/pages/login/login.vue b/pages/login/login.vue index 1a7c109..b5b9331 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -6,14 +6,21 @@ + diff --git a/pages/settings/settings.vue b/pages/settings/settings.vue index cd40f78..7ae3bca 100644 --- a/pages/settings/settings.vue +++ b/pages/settings/settings.vue @@ -1,23 +1,205 @@ diff --git a/pages/user/user.vue b/pages/user/user.vue index 4877493..f946741 100644 --- a/pages/user/user.vue +++ b/pages/user/user.vue @@ -8,6 +8,7 @@