Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
飞
飞鹤小程序
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
FH
飞鹤小程序
Commits
c443d5d7
Commit
c443d5d7
authored
Jun 06, 2025
by
zcc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 更新request.js
parent
064671a6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
89 additions
and
25 deletions
+89
-25
request.js
api/request.js
+38
-5
user.js
api/user.js
+1
-1
TabBar.vue
components/TabBar.vue
+7
-1
main.js
main.js
+3
-3
global.js
stores/global.js
+23
-0
user.js
stores/user.js
+17
-15
No files found.
api/request.js
View file @
c443d5d7
import
{
useGlobalStore
}
from
'../stores/global.js'
;
import
{
storeToRefs
}
from
'pinia'
;
import
{
HTTP_STATUS
}
from
'./config.js'
const
globalStore
=
useGlobalStore
();
const
{
cuk
}
=
storeToRefs
(
globalStore
);
// request.js
// 通常可以吧 baseUrl 单独放在一个 js 文件了
const
baseUrl
=
"http
s://docs.dui88.com/mock/1956
"
;
const
baseUrl
=
"http
://172.16.230.108:7777/pmall
"
;
const
request
=
(
options
=
{})
=>
{
// 在这里可以对请求头进行一些设置
...
...
@@ -14,13 +29,31 @@ const request = (options = {}) => {
url
:
baseUrl
+
options
.
url
||
""
,
method
:
options
.
type
||
"GET"
,
data
:
options
.
data
||
{},
header
:
options
.
header
||
{},
header
:
{
...
options
.
header
,
cuk
:
cuk
.
value
||
undefined
},
})
.
then
((
data
)
=>
{
.
then
((
data
)
=>
{
// console.log('request data ===>', data);
// const [err, res] = data;
if
(
data
.
statusCode
!==
HTTP_STATUS
.
SUCCESS
)
{
uni
.
showToast
({
title
:
data
.
errMsg
,
icon
:
'error'
});
reject
(
data
);
}
else
if
(
!
data
.
data
?.
ok
)
{
uni
.
showToast
({
title
:
data
.
data
?.
message
,
icon
:
'error'
});
reject
(
data
.
data
);
}
else
{
resolve
(
data
.
data
);
}
// const [err, res] = data;
// TODO uni.showToast errMsg
resolve
(
data
.
data
);
})
.
catch
((
error
)
=>
{
reject
(
error
);
...
...
api/user.js
View file @
c443d5d7
...
...
@@ -37,4 +37,4 @@ export const autoLoginByCode = (code) =>
* @param {*} data : {phoneEncryptedData, phoneIv, code}
* @returns
*/
export
const
fetchAutoPhone
=
(
data
)
=>
api
.
ge
t
(
'/c/login/authPhone'
,
data
);
export
const
fetchAutoPhone
=
(
data
)
=>
api
.
pos
t
(
'/c/login/authPhone'
,
data
);
components/TabBar.vue
View file @
c443d5d7
...
...
@@ -19,7 +19,9 @@
</
template
>
<
script
setup
>
import
{
ref
,
getCurrentInstance
}
from
"vue"
;
import
{
ref
,
getCurrentInstance
,
onMounted
}
from
"vue"
;
import
{
useUserStore
}
from
'@/stores/user.js'
;
const
userStore
=
useUserStore
();
const
{
proxy
}
=
getCurrentInstance
();
const
$baseUrl
=
proxy
.
$baseUrl
;
...
...
@@ -62,6 +64,10 @@ const handleTabClick = (index, item) => {
currentIndex
.
value
=
index
;
emit
(
"tabClick"
,
{
index
,
item
});
};
onMounted
(()
=>
{
userStore
.
wxAutoLogin
();
})
</
script
>
<
style
lang=
"less"
scoped
>
...
...
main.js
View file @
c443d5d7
import
App
from
"./App"
;
import
apiRequest
from
"@/api/request.js"
;
//
import apiRequest from "@/api/request.js";
import
*
as
Pinia
from
'pinia'
;
const
BASE_URL
=
'https://duiba.oss-cn-hangzhou.aliyuncs.com/fh/'
;
...
...
@@ -11,7 +11,7 @@ import "./uni.promisify.adaptor";
// 全局挂载后使用
Vue
.
prototype
.
$api
=
apiRequest
.
api
;
//
Vue.prototype.$api = apiRequest.api;
Vue
.
prototype
.
$baseUrl
=
BASE_URL
;
Vue
.
config
.
productionTip
=
false
;
...
...
@@ -28,7 +28,7 @@ import { createSSRApp } from "vue";
export
function
createApp
()
{
const
app
=
createSSRApp
(
App
);
app
.
use
(
Pinia
.
createPinia
());
app
.
config
.
globalProperties
.
$api
=
apiRequest
.
api
;
//
app.config.globalProperties.$api = apiRequest.api;
app
.
config
.
globalProperties
.
$baseUrl
=
BASE_URL
;
return
{
app
,
...
...
stores/global.js
0 → 100644
View file @
c443d5d7
import
{
defineStore
}
from
'pinia'
;
const
cuk
=
uni
.
getStorageSync
(
'cuk'
)
export
const
useGlobalStore
=
defineStore
(
'global'
,
{
state
:
()
=>
{
return
{
cuk
:
cuk
,
// 用户登录后获取的凭证,获取用户、宝宝信息接口时使用
};
},
actions
:
{
/**
* 设置用户cuk
* @param {Object} cuk
*/
setCuk
(
cuk
)
{
this
.
cuk
=
cuk
;
uni
.
setStorageSync
(
'cuk'
,
cuk
);
}
},
});
\ No newline at end of file
stores/user.js
View file @
c443d5d7
...
...
@@ -7,11 +7,14 @@ import {
fetchBabyInfo
,
fetchAutoPhone
}
from
'../api/user.js'
;
import
{
useGlobalStore
}
from
'./global.js'
;
const
globalStore
=
useGlobalStore
();
export
const
useUserStore
=
defineStore
(
'userInfo'
,
{
state
:
()
=>
{
return
{
cuk
:
null
,
// 用户登录后获取的凭证,获取用户、宝宝信息接口时使用
userInfo
:
null
,
babyInfo
:
null
,
};
...
...
@@ -38,14 +41,14 @@ export const useUserStore = defineStore('userInfo', {
* @param {Object} data : {encryptedData, iv, code}
* @returns
*/
async
phoneCallback
(
data
)
{
async
phoneCallback
(
data
)
{
// 用户手机授权
await
fetchAutoPhone
({
phoneEncryptedData
:
data
.
encryptedData
,
phoneIv
:
data
.
iv
,
code
:
data
.
code
,
});
// 授权注册成功后做一次登录
});
// 授权注册成功后做一次登录
this
.
wxAutoLogin
();
},
...
...
@@ -53,28 +56,26 @@ export const useUserStore = defineStore('userInfo', {
* 获取用户信息
*/
async
loadUserInfo
()
{
if
(
!
this
.
cuk
)
{
return
;
}
const
{
data
}
=
await
fetchUserInfo
(
this
.
cuk
);
}
=
await
fetchUserInfo
();
console
.
log
(
'userInfo'
,
data
);
this
.
userInfo
=
data
;
if
(
data
?.
memberId
!==
'not_login'
)
{
this
.
userInfo
=
data
;
}
},
/**
* 获取宝宝信息
*/
async
loadBabyInfo
()
{
if
(
!
this
.
cuk
)
{
return
;
}
const
{
data
}
=
await
fetchBabyInfo
(
this
.
cuk
);
}
=
await
fetchBabyInfo
();
console
.
log
(
'babyInfo'
,
data
);
this
.
babyInfo
=
data
;
if
(
data
?.
memberId
!==
'not_login'
)
{
this
.
babyInfo
=
data
;
}
},
/**
...
...
@@ -88,7 +89,8 @@ export const useUserStore = defineStore('userInfo', {
console
.
log
(
'autoLoginByCode'
,
data
);
// 如果登录成功,获取用户信息和宝宝信息,更新到state中,方便全局使用
if
(
data
&&
data
.
cuk
)
{
this
.
cuk
=
data
.
cuk
;
globalStore
.
setCuk
(
data
.
cuk
);
this
.
loadUserInfo
();
this
.
loadBabyInfo
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment