Commit 2f6bd6e7647fe1c398285d3a1a1002595fd7b8af
Merge branch 'dev-ft' into 'main'
fix:修复所有请求接口无基础路径问题 See merge request huang/thingskit-app!21
Showing
5 changed files
with
107 additions
and
58 deletions
... | ... | @@ -15,8 +15,8 @@ |
15 | 15 | <block v-for="(item, index) in list" :key="index"> |
16 | 16 | <!-- 自定义icon --> |
17 | 17 | <u-tabbar-item :text="item.name" :badge="item.badge" :dot="item.dot" :badgeStyle="item.badgeStyle"> |
18 | - <view slot="active-icon"><image style="width:30rpx;height: 30rpx;" :src="item.iconFill" mode=""></image></view> | |
19 | - <view slot="inactive-icon"><image style="width:30rpx;height: 30rpx;" :src="item.icon" mode=""></image></view> | |
18 | + <view slot="active-icon"><image style="width:50rpx;height: 50rpx;" :src="item.iconFill" mode=""></image></view> | |
19 | + <view slot="inactive-icon"><image style="width:50rpx;height: 50rpx;" :src="item.icon" mode=""></image></view> | |
20 | 20 | </u-tabbar-item> |
21 | 21 | </block> |
22 | 22 | </u-tabbar> | ... | ... |
... | ... | @@ -2,17 +2,12 @@ import { |
2 | 2 | getTabbarHeight |
3 | 3 | } from '@/plugins/utils'; |
4 | 4 | let baseUrl = ""; |
5 | -let imageUrl = '' | |
6 | 5 | if (process.env.NODE_ENV === 'development') { |
7 | 6 | // 开发环境 |
8 | 7 | baseUrl = 'http://47.99.141.212:8080/api' |
9 | - // baseUrl = 'http://192.168.10.103:8080/api' | |
10 | - imageUrl='http://192.168.10.103:8080/api' | |
11 | - // baseUrl = 'http://192.168.1.228/fan_php/public/index.php' | |
12 | 8 | } else if (process.env.NODE_ENV === 'production') { |
13 | 9 | // 生产环境 |
14 | - baseUrl = 'https://api.yichengshi.cn' | |
15 | - imageUrl='http://47.99.141.212:8080/api' | |
10 | + baseUrl = 'http://47.99.141.212:8080/api' | |
16 | 11 | } |
17 | 12 | |
18 | 13 | let systemInfo = { |
... | ... | @@ -43,7 +38,6 @@ console.log(systemInfo, 'systemInfo') |
43 | 38 | const courtConfig = { |
44 | 39 | publicAppId: '', //公众号appId |
45 | 40 | baseUrl: baseUrl, //域名 |
46 | - imageUrl:imageUrl,//上传图片 | |
47 | 41 | systemInfo: systemInfo, //系统信息 |
48 | 42 | mapData: { |
49 | 43 | key: '', //地图key | ... | ... |
... | ... | @@ -6,19 +6,10 @@ import { |
6 | 6 | |
7 | 7 | // 初始化请求配置 |
8 | 8 | uni.$u.http.setConfig((config) => { |
9 | - let token = store.state.userInfo.isToken || (uni.getStorageSync('userInfo').isToken || undefined) | |
9 | + const token = store.state.userInfo.isToken || (uni.getStorageSync('userInfo').isToken || undefined) | |
10 | 10 | // #ifdef H5 |
11 | 11 | window.sessionStorage.getItem('userInfo').isToken; |
12 | 12 | // #endif |
13 | - if (!token) { | |
14 | - uni.showToast({ | |
15 | - title: '请先登录', | |
16 | - icon: 'none' | |
17 | - }); | |
18 | - return uni.reLaunch({ | |
19 | - url: '/pages/public/login' | |
20 | - }) | |
21 | - } | |
22 | 13 | /* config 为默认全局配置*/ |
23 | 14 | config.baseURL = base.baseUrl; /* 根域名 */ |
24 | 15 | config.header = { |
... | ... | @@ -40,9 +31,10 @@ uni.$u.http.interceptors.request.use((config) => { // å¯ä½¿ç”¨async await åšå¼ |
40 | 31 | config.data = config.data || {} |
41 | 32 | // 根据custom参数中配置的是否需要token,添加对应的请求头 |
42 | 33 | if (config?.custom?.auth) { |
43 | - config.header.Authorization = 'Bearer ' + store.state.userInfo.isToken | |
34 | + config.header.Authorization = 'Bearer ' + store.state.userInfo.isToken || (uni.getStorageSync( | |
35 | + 'userInfo').isToken || undefined) | |
44 | 36 | } |
45 | - // console.log("请求开始", config); | |
37 | + console.log("请求开始", config); | |
46 | 38 | if (config?.custom?.load) { |
47 | 39 | //打开加载动画 |
48 | 40 | store.commit("setLoadingShow", true); |
... | ... | @@ -105,7 +97,7 @@ uni.$u.http.interceptors.response.use((response) => { |
105 | 97 | }) |
106 | 98 | store.commit('emptyUserInfo') |
107 | 99 | } else if (message == 'Invalid username or password') { |
108 | - errorData = '请重新登录' | |
100 | + errorData = '用户名或者密码无效' | |
109 | 101 | uni.reLaunch({ |
110 | 102 | url: '/pages/public/login' |
111 | 103 | }) | ... | ... |
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | <!-- 公共组件-每个页面必须引入 --> |
4 | 4 | <public-module></public-module> |
5 | 5 | <view class="form-page"> |
6 | - <u--form labelPosition="left" :model="feedbackData" :rules="rules" ref="form1"> | |
6 | + <u--form labelPosition="left" :model="feedbackData" :rules="rules" ref="myfeedBackFormRef"> | |
7 | 7 | <u-form-item required label="主题" prop="feedbackInfo.title" borderBottom ref="item1"> |
8 | 8 | <u--input placeholder="请输入主题" v-model="feedbackData.feedbackInfo.title" border="none"></u--input> |
9 | 9 | </u-form-item> |
... | ... | @@ -42,6 +42,7 @@ |
42 | 42 | <script> |
43 | 43 | import fTabbar from '@/components/module/f-tabbar/f-tabbar'; |
44 | 44 | import baseUrl from '@/config/baseUrl.js'; |
45 | +import { mapState } from 'vuex'; | |
45 | 46 | |
46 | 47 | export default { |
47 | 48 | components: { |
... | ... | @@ -77,6 +78,21 @@ export default { |
77 | 78 | trigger: ['change', 'blur'] |
78 | 79 | } |
79 | 80 | ], |
81 | + 'feedbackInfo.name': [ | |
82 | + { | |
83 | + type: 'string', | |
84 | + required: true, | |
85 | + message: '请填写姓名', | |
86 | + trigger: ['blur', 'change'] | |
87 | + }, | |
88 | + { | |
89 | + validator: (rule, value, callback) => { | |
90 | + return uni.$u.test.chinese(value); | |
91 | + }, | |
92 | + message: '姓名必须为中文', | |
93 | + trigger: ['change', 'blur'] | |
94 | + } | |
95 | + ], | |
80 | 96 | 'feedbackInfo.phone': [ |
81 | 97 | { |
82 | 98 | type: 'string', |
... | ... | @@ -85,7 +101,6 @@ export default { |
85 | 101 | trigger: ['blur', 'change'] |
86 | 102 | }, |
87 | 103 | { |
88 | - // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明 | |
89 | 104 | validator: (rule, value, callback) => { |
90 | 105 | return uni.$u.test.mobile(value); |
91 | 106 | }, |
... | ... | @@ -101,7 +116,6 @@ export default { |
101 | 116 | trigger: ['blur', 'change'] |
102 | 117 | }, |
103 | 118 | { |
104 | - // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明 | |
105 | 119 | validator: (rule, value, callback) => { |
106 | 120 | return uni.$u.test.email(value); |
107 | 121 | }, |
... | ... | @@ -131,6 +145,9 @@ export default { |
131 | 145 | // 隐藏原生的tabbar |
132 | 146 | uni.hideTabBar(); |
133 | 147 | }, |
148 | + computed: { | |
149 | + ...mapState(['userInfo']) | |
150 | + }, | |
134 | 151 | methods: { |
135 | 152 | // 删除图片 |
136 | 153 | deletePic(event) { |
... | ... | @@ -138,7 +155,6 @@ export default { |
138 | 155 | }, |
139 | 156 | // 新增图片 |
140 | 157 | async afterRead(event) { |
141 | - // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式 | |
142 | 158 | let lists = [].concat(event.file); |
143 | 159 | let fileListLen = this[`fileList${event.name}`].length; |
144 | 160 | lists.map(item => { |
... | ... | @@ -164,25 +180,22 @@ export default { |
164 | 180 | } |
165 | 181 | }, |
166 | 182 | uploadFilePromise(url) { |
167 | - // store.state.userInfo.isToken || | |
168 | 183 | let token; |
169 | - token = uni.getStorageSync('userInfo').isToken || undefined; | |
184 | + token = this.userInfo.isToken || uni.getStorageSync('userInfo').isToken || undefined; | |
170 | 185 | // #ifdef H5 |
171 | 186 | token = window.sessionStorage.getItem('userInfo').isToken; |
172 | 187 | // #endif |
173 | 188 | if (!token) return uni.$u.toast('请登录后上传图片'); |
174 | 189 | return new Promise((resolve, reject) => { |
175 | 190 | let a = uni.uploadFile({ |
176 | - url: 'http://47.99.141.212:8080/api/yt/oss/upload', | |
191 | + url: `${baseUrl.baseUrl}/yt/oss/upload`, | |
177 | 192 | filePath: url, |
178 | 193 | name: 'file', |
179 | 194 | header: { |
180 | 195 | 'content-type': 'multipart/form-data', |
181 | 196 | Authorization: 'Bearer ' + token |
182 | 197 | }, |
183 | - formData: { | |
184 | - user: 'test' | |
185 | - }, | |
198 | + formData: {}, | |
186 | 199 | success: res => { |
187 | 200 | setTimeout(() => { |
188 | 201 | if (res) { |
... | ... | @@ -198,33 +211,40 @@ export default { |
198 | 211 | }); |
199 | 212 | }, |
200 | 213 | submit() { |
201 | - let contactInfo = { | |
202 | - qq: this.feedbackData.feedbackInfo?.qq, | |
203 | - email: this.feedbackData.feedbackInfo?.email, | |
204 | - phone: this.feedbackData.feedbackInfo?.phone | |
205 | - }; | |
206 | - let httpData = { | |
207 | - title: this.feedbackData.feedbackInfo.title, | |
208 | - name: this.feedbackData.feedbackInfo.name, | |
209 | - contact: JSON.stringify(contactInfo), | |
210 | - images: this.feedbackData.feedbackInfo.images.length == 0 ? '' : JSON.stringify(this.feedbackData.feedbackInfo.images), | |
211 | - message: this.feedbackData.feedbackInfo.message | |
212 | - }; | |
213 | - uni.$u.http | |
214 | - .post('/yt/opinion', httpData) | |
214 | + this.$refs.myfeedBackFormRef | |
215 | + .validate() | |
215 | 216 | .then(res => { |
216 | - if (res) { | |
217 | - uni.showToast({ | |
218 | - title: '意见反馈提交成功~', | |
219 | - icon: 'none' | |
217 | + let contactInfo = { | |
218 | + qq: this.feedbackData.feedbackInfo?.qq, | |
219 | + email: this.feedbackData.feedbackInfo?.email, | |
220 | + phone: this.feedbackData.feedbackInfo?.phone | |
221 | + }; | |
222 | + let httpData = { | |
223 | + title: this.feedbackData.feedbackInfo.title, | |
224 | + name: this.feedbackData.feedbackInfo.name, | |
225 | + contact: JSON.stringify(contactInfo), | |
226 | + images: this.feedbackData.feedbackInfo.images.length == 0 ? '' : JSON.stringify(this.feedbackData.feedbackInfo.images), | |
227 | + message: this.feedbackData.feedbackInfo.message | |
228 | + }; | |
229 | + uni.$u.http | |
230 | + .post('/yt/opinion', httpData) | |
231 | + .then(res => { | |
232 | + if (res) { | |
233 | + uni.showToast({ | |
234 | + title: '意见反馈提交成功~', | |
235 | + icon: 'none' | |
236 | + }); | |
237 | + setTimeout(() => { | |
238 | + uni.navigateBack(); | |
239 | + }, 500); | |
240 | + } | |
241 | + }) | |
242 | + .catch(e => { | |
243 | + uni.$u.toast(e.data?.message); | |
220 | 244 | }); |
221 | - setTimeout(() => { | |
222 | - uni.navigateBack(); | |
223 | - }, 500); | |
224 | - } | |
225 | 245 | }) |
226 | - .catch(e => { | |
227 | - uni.$u.toast(e.data?.message); | |
246 | + .catch(errors => { | |
247 | + uni.$u.toast('校验失败'); | |
228 | 248 | }); |
229 | 249 | } |
230 | 250 | } | ... | ... |
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | <view class="set-page"> |
3 | 3 | <!-- 公共组件-每个页面必须引入 --> |
4 | 4 | <public-module></public-module> |
5 | - <view class="u-flex set-main"> | |
5 | + <view @click="upAvatar" class="u-flex set-main"> | |
6 | 6 | <view class="main-image"><image class="image" :src="avatar || '../../static/default-avatar.png'"></image></view> |
7 | 7 | <view class="main-right-image"><image class="image" src="../../static/arrow-right.png"></image></view> |
8 | 8 | </view> |
... | ... | @@ -111,7 +111,6 @@ export default { |
111 | 111 | trigger: ['blur', 'change'] |
112 | 112 | }, |
113 | 113 | { |
114 | - // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明 | |
115 | 114 | validator: (rule, value, callback) => { |
116 | 115 | return uni.$u.test.email(value); |
117 | 116 | }, |
... | ... | @@ -135,6 +134,50 @@ export default { |
135 | 134 | } |
136 | 135 | }, |
137 | 136 | methods: { |
137 | + // 修改头像 | |
138 | + upAvatar() { | |
139 | + var that = this; | |
140 | + uni.chooseImage({ | |
141 | + count: 1, | |
142 | + sourceType: ['camera', 'album'], | |
143 | + success: res => { | |
144 | + const tempFilePaths = res.tempFilePaths; | |
145 | + //限制上传的图片大小不超过2M | |
146 | + let resSize = res.tempFiles[0].size; | |
147 | + if (resSize > 2097152) { | |
148 | + uni.showToast({ | |
149 | + title: '上传的图片大小不能超过2M', | |
150 | + icon: 'none', | |
151 | + duration: 2000, | |
152 | + mask: true | |
153 | + }); | |
154 | + return; | |
155 | + } | |
156 | + //限制图片类型 | |
157 | + let resType = res.tempFiles[0].type.substring(0, 5); | |
158 | + if (resType != 'image' || res.tempFiles[0].type.substring(6, 7) == 'g') { | |
159 | + uni.showToast({ | |
160 | + title: '限制图片类型以及过滤git图', | |
161 | + icon: 'none', | |
162 | + duration: 2000, | |
163 | + mask: true | |
164 | + }); | |
165 | + return; | |
166 | + } | |
167 | + uni.$u.http | |
168 | + .upload('/yt/oss/upload', { | |
169 | + filePath: tempFilePaths[0], | |
170 | + name: 'file' | |
171 | + }) | |
172 | + .then(res => { | |
173 | + if (res) { | |
174 | + that.avatar = res.fileStaticUri; | |
175 | + return uni.$u.toast('头像上传成功'); | |
176 | + } | |
177 | + }); | |
178 | + } | |
179 | + }); | |
180 | + }, | |
138 | 181 | onSubmitFunc() { |
139 | 182 | this.$refs.myInfoFormRef |
140 | 183 | .validate() | ... | ... |