1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| import config from '@/config/index.js'
|
| /**
| * 游客可访问接口专用请求,避免被本地登录态刷新、旧 token、请求队列影响。
| * timeout 默认 10 秒,冷启动等对速度敏感的接口可传入更短超时。
| */
| export function publicGet(url, data = {}, timeout = 10000) {
| const requestUrl = `${config.BASE_URL}${url}`
| return new Promise((resolve, reject) => {
| uni.request({
| url: requestUrl,
| method: 'GET',
| data,
| timeout,
| header: {
| 'content-type': 'application/json',
| lang: uni.getStorageSync('locale') === 'zh-Hans' ? 'zh_CN' : 'zh-tw',
| },
| success: (res) => {
| resolve(res.data || {})
| },
| fail: (error) => {
| reject(error)
| },
| })
| })
| }
| /**
| * 发起游客可访问的 POST 请求。
| */
| export function publicPost(url, data = {}) {
| const requestUrl = `${config.BASE_URL}${url}`
| return new Promise((resolve, reject) => {
| uni.request({
| url: requestUrl,
| method: 'POST',
| data,
| timeout: 10000,
| header: {
| 'content-type': 'application/json',
| lang: uni.getStorageSync('locale') === 'zh-Hans' ? 'zh_CN' : 'zh-tw',
| },
| success: (res) => {
| resolve(res.data || {})
| },
| fail: (error) => {
| reject(error)
| },
| })
| })
| }
|
|