From e25d8e073bddcb8709b6c2faddf9df5456cff7ef Mon Sep 17 00:00:00 2001
From: sundongyu <2811054731@qq.com>
Date: Fri, 19 Apr 2024 15:01:14 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E8=AF=B7=E6=B1=82?=
=?UTF-8?q?=E5=9F=BA=E5=9C=B0=E5=9D=80=E5=92=8C=E8=AF=B7=E6=8F=90=E7=A4=BA?=
=?UTF-8?q?=E7=9A=84=E5=B0=81=E8=A3=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.prettierrc | 8 ++++++++
main.js | 15 +++++++-------
package-lock.json | 16 ++++++++++++++-
package.json | 3 ++-
pages.json | 7 +++++++
pages/login/index.vue | 21 +++++++++++++++++++
utils/http.js | 47 +++++++++++++++++++++++++++++++++++++++++++
utils/utils.js | 17 ++++++++++++++++
8 files changed, 125 insertions(+), 9 deletions(-)
create mode 100644 .prettierrc
create mode 100644 pages/login/index.vue
create mode 100644 utils/http.js
create mode 100644 utils/utils.js
diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..b957c2a
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,8 @@
+{
+ "printWidth": 80,
+ "tabWidth": 2,
+ "useTabs": false,
+ "semi": false,
+ "singleQuote": true,
+ "vueIndentScriptAndStyle": true,
+}
\ No newline at end of file
diff --git a/main.js b/main.js
index 1c10c11..768ece2 100644
--- a/main.js
+++ b/main.js
@@ -1,11 +1,12 @@
-import App from './App';
-import uviewPlus from '@/uni_modules/uview-plus';
+import App from './App'
+import uviewPlus from '@/uni_modules/uview-plus'
+import '@/utils/utils'
-import { createSSRApp } from 'vue';
+import { createSSRApp } from 'vue'
export function createApp() {
- const app = createSSRApp(App);
- app.use(uviewPlus);
+ const app = createSSRApp(App)
+ app.use(uviewPlus)
return {
- app
- };
+ app,
+ }
}
diff --git a/package-lock.json b/package-lock.json
index 0ad97f2..f95d5a9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6,13 +6,19 @@
"": {
"dependencies": {
"clipboard": "^2.0.11",
- "dayjs": "^1.11.10"
+ "dayjs": "^1.11.10",
+ "luch-request": "^3.1.1"
},
"devDependencies": {
"sass": "^1.75.0",
"sass-loader": "^14.2.1"
}
},
+ "node_modules/@dcloudio/types": {
+ "version": "2.6.12",
+ "resolved": "https://registry.npmjs.org/@dcloudio/types/-/types-2.6.12.tgz",
+ "integrity": "sha512-mrCMwcINy1IFjU9VUqLeWBkj404yWs5paLDttBcA+eqUjanuUQbBcTVPqlrGgkyzLXDcV2oDDZRSNxNpXi4kMQ=="
+ },
"node_modules/anymatch": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
@@ -188,6 +194,14 @@
"node": ">=0.12.0"
}
},
+ "node_modules/luch-request": {
+ "version": "3.1.1",
+ "resolved": "https://registry.npmjs.org/luch-request/-/luch-request-3.1.1.tgz",
+ "integrity": "sha512-p7+mlcEtgRcd0OfXC4XZbyiwSr1XgCeqNT7LlVUjnk7InYl/8d5Rk7BUqAYNA2WRafI1wRIUQWRWZRpeUwWR0w==",
+ "dependencies": {
+ "@dcloudio/types": "^2.0.16"
+ }
+ },
"node_modules/neo-async": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz",
diff --git a/package.json b/package.json
index 4c0d297..7dd423d 100644
--- a/package.json
+++ b/package.json
@@ -5,6 +5,7 @@
},
"dependencies": {
"clipboard": "^2.0.11",
- "dayjs": "^1.11.10"
+ "dayjs": "^1.11.10",
+ "luch-request": "^3.1.1"
}
}
diff --git a/pages.json b/pages.json
index bec07dc..29e8dc2 100644
--- a/pages.json
+++ b/pages.json
@@ -90,6 +90,13 @@
"navigationBarTitleText": "高手详情",
"navigationStyle": "custom"
}
+ },
+ {
+ "path": "pages/login/index",
+ "style": {
+ "navigationBarTitleText": "登录",
+ "navigationStyle": "custom"
+ }
}
],
"globalStyle": {
diff --git a/pages/login/index.vue b/pages/login/index.vue
new file mode 100644
index 0000000..3451416
--- /dev/null
+++ b/pages/login/index.vue
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/utils/http.js b/utils/http.js
new file mode 100644
index 0000000..dbc33f4
--- /dev/null
+++ b/utils/http.js
@@ -0,0 +1,47 @@
+// 导入模块
+import Request from 'luch-request'
+
+// 实例化网络请求
+const http = new Request({
+ // 接口基地址
+ baseURL: '',
+ custom: {
+ loading: true,
+ },
+})
+
+//配置请求拦截器
+http.interceptors.request.use(
+ function (config) {
+ // 显示加载状态提示
+ if (config.custom.loading) {
+ uni.showLoading({ title: '正在加载...', mask: true })
+ }
+ // 定义头信息,并保证接口调用传递的头信息
+ // 能够覆盖在拦截器定义的头信息
+ config.header = {
+ Authorization: 'token',
+ ...config.header,
+ }
+
+ return config
+ },
+ function (error) {
+ return Promise.reject(error)
+ }
+)
+// 响应拦截器
+http.interceptors.response.use(
+ function ({ statusCode, data, config }) {
+ // 隐藏加载状态提示
+ uni.hideLoading()
+ // 解构出响应主体
+ return data
+ },
+ function (error) {
+ return Promise.reject(error)
+ }
+)
+
+// 导出配置好的模网络模块
+export { http }
diff --git a/utils/utils.js b/utils/utils.js
new file mode 100644
index 0000000..1097202
--- /dev/null
+++ b/utils/utils.js
@@ -0,0 +1,17 @@
+/**
+ * 项目中会用的一系列的工具方法
+ */
+uni.utils = {
+ /**
+ * 用户反馈(轻提示)
+ * @param {string} title 提示文字内容
+ * @param {string} icon 提示图标类型
+ */
+ toast(title = '数据加载失败!', icon = 'none') {
+ uni.showToast({
+ title,
+ icon,
+ mask: true,
+ })
+ },
+}