feat
This commit is contained in:
parent
b58fe9df30
commit
32c3cd8936
4
.env
4
.env
|
@ -2,10 +2,10 @@
|
|||
MALL_VERSION = v1.0.0
|
||||
|
||||
# 后端接口 - 正式环境(通过 process.env.NODE_ENV 非 development)
|
||||
MALL_BASE_URL = http://api-dashboard.yudao.iocoder.cn
|
||||
MALL_BASE_URL = https://mall.jiandyb.cn:49011
|
||||
|
||||
# 后端接口 - 测试环境(通过 process.env.NODE_ENV = development)
|
||||
MALL_DEV_BASE_URL = https://mall-baclend-local.jiandyb9834.xyz
|
||||
MALL_DEV_BASE_URL = https://mall.jiandyb.cn:49011
|
||||
|
||||
# 后端接口前缀(一般不建议调整)
|
||||
MALL_API_PATH = /merchant-api
|
||||
|
|
|
@ -1,56 +1,57 @@
|
|||
import request from '@/peach/request'
|
||||
|
||||
const AuthUtil = {
|
||||
smsLogin: (data) => {
|
||||
return request({
|
||||
url: '/particulars/member/auth/sms-login',
|
||||
method: 'POST',
|
||||
data,
|
||||
custom: {
|
||||
showSuccess: true,
|
||||
loadingMsg: '登陆中',
|
||||
successMsg: '登陆成功',
|
||||
auth: false,
|
||||
},
|
||||
})
|
||||
},
|
||||
// 退出登陆
|
||||
logout: () => {
|
||||
return request({
|
||||
url: '/particulars/member/auth/logout',
|
||||
method: 'POST',
|
||||
})
|
||||
},
|
||||
// 发送手机验证码
|
||||
sendSmsCode: (mobile, scene) => {
|
||||
return request({
|
||||
url: '/member/auth/send-sms-code',
|
||||
method: 'POST',
|
||||
data: {
|
||||
mobile,
|
||||
scene,
|
||||
},
|
||||
custom: {
|
||||
loadingMsg: '发送中',
|
||||
showSuccess: true,
|
||||
successMsg: '发送成功',
|
||||
},
|
||||
})
|
||||
},
|
||||
// 刷新令牌
|
||||
refreshToken: (refreshToken) => {
|
||||
return request({
|
||||
url: '/particulars/member/auth/refresh-token',
|
||||
method: 'POST',
|
||||
params: {
|
||||
refreshToken,
|
||||
},
|
||||
custom: {
|
||||
loading: false, // 不用加载中
|
||||
showError: false, // 不展示错误提示
|
||||
},
|
||||
})
|
||||
},
|
||||
smsLogin: (data) => {
|
||||
return request({
|
||||
url: '/particulars/member/auth/sms-login',
|
||||
method: 'POST',
|
||||
data,
|
||||
custom: {
|
||||
showSuccess: true,
|
||||
loadingMsg: '登陆中',
|
||||
successMsg: '登陆成功',
|
||||
auth: false,
|
||||
},
|
||||
})
|
||||
},
|
||||
// 退出登陆
|
||||
logout: () => {
|
||||
return request({
|
||||
url: '/particulars/member/auth/logout',
|
||||
method: 'POST',
|
||||
})
|
||||
},
|
||||
// 发送手机验证码
|
||||
sendSmsCode: (mobile, scene) => {
|
||||
return request({
|
||||
url: '/member/auth/send-sms-code',
|
||||
method: 'POST',
|
||||
data: {
|
||||
mobile,
|
||||
scene,
|
||||
},
|
||||
custom: {
|
||||
loadingMsg: '发送中',
|
||||
showSuccess: true,
|
||||
successMsg: '发送成功',
|
||||
auth: false,
|
||||
},
|
||||
})
|
||||
},
|
||||
// 刷新令牌
|
||||
refreshToken: (refreshToken) => {
|
||||
return request({
|
||||
url: '/particulars/member/auth/refresh-token',
|
||||
method: 'POST',
|
||||
params: {
|
||||
refreshToken,
|
||||
},
|
||||
custom: {
|
||||
loading: false, // 不用加载中
|
||||
showError: false, // 不展示错误提示
|
||||
},
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
export default AuthUtil
|
||||
|
|
|
@ -12,15 +12,15 @@ import AuthUtil from '@/peach/api/member/auth'
|
|||
* @returns {Type}
|
||||
*/
|
||||
export function showAuthModal(type = 'smsLogin') {
|
||||
const modal = $store('modal')
|
||||
if (modal.auth !== '') {
|
||||
closeAuthModal()
|
||||
setTimeout(() => {
|
||||
modal.auth = type
|
||||
}, 100)
|
||||
} else {
|
||||
modal.auth = type
|
||||
}
|
||||
const modal = $store('modal')
|
||||
if (modal.auth !== '') {
|
||||
closeAuthModal()
|
||||
setTimeout(() => {
|
||||
modal.auth = type
|
||||
}, 100)
|
||||
} else {
|
||||
modal.auth = type
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,7 @@ export function showAuthModal(type = 'smsLogin') {
|
|||
* @returns {Type}
|
||||
*/
|
||||
export function closeAuthModal() {
|
||||
$store('modal').auth = ''
|
||||
$store('modal').auth = ''
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ export function closeAuthModal() {
|
|||
* @returns {Type}
|
||||
*/
|
||||
export function showShareModal() {
|
||||
$store('modal').share = true
|
||||
$store('modal').share = true
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ export function showShareModal() {
|
|||
* @returns {Type}
|
||||
*/
|
||||
export function closeShareModal() {
|
||||
$store('modal').share = false
|
||||
$store('modal').share = false
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,7 +60,7 @@ export function closeShareModal() {
|
|||
* @returns {Type}
|
||||
*/
|
||||
export function showMenuTools() {
|
||||
$store('modal').menu = true
|
||||
$store('modal').menu = true
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,7 +71,7 @@ export function showMenuTools() {
|
|||
*/
|
||||
// 关闭快捷菜单
|
||||
export function closeMenuTools() {
|
||||
$store('modal').menu = false
|
||||
$store('modal').menu = false
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,46 +82,48 @@ export function closeMenuTools() {
|
|||
* @returns {Type}
|
||||
*/
|
||||
export function getSmsCode(event, mobile) {
|
||||
const modalStore = $store('modal')
|
||||
const lastSendTimer = modalStore.lastTimer[event]
|
||||
if (typeof lastSendTimer === 'undefined') {
|
||||
$helper.toast('短信发送事件错误')
|
||||
return
|
||||
}
|
||||
const modalStore = $store('modal')
|
||||
const lastSendTimer = modalStore.lastTimer[event]
|
||||
|
||||
const duration = dayjs().unix() - lastSendTimer
|
||||
const canSend = duration >= 60
|
||||
if (!canSend) {
|
||||
$helper.toast('请稍后再试')
|
||||
return
|
||||
}
|
||||
// 只有 mobile 非空时才校验。因为部分场景(修改密码),不需要输入手机
|
||||
if (mobile && !test.mobile(mobile)) {
|
||||
$helper.toast('手机号码格式不正确')
|
||||
return
|
||||
}
|
||||
if (typeof lastSendTimer === 'undefined') {
|
||||
$helper.toast('短信发送事件错误')
|
||||
return
|
||||
}
|
||||
|
||||
// 发送验证码 + 更新上次发送验证码时间
|
||||
let scene = -1
|
||||
switch (event) {
|
||||
case 'resetPassword':
|
||||
scene = 4
|
||||
break
|
||||
case 'changePassword':
|
||||
scene = 3
|
||||
break
|
||||
case 'changeMobile':
|
||||
scene = 2
|
||||
break
|
||||
case 'smsLogin':
|
||||
scene = 1
|
||||
break
|
||||
}
|
||||
AuthUtil.sendSmsCode(mobile, scene).then((res) => {
|
||||
if (res.code === 0) {
|
||||
modalStore.lastTimer[event] = dayjs().unix()
|
||||
}
|
||||
})
|
||||
const duration = dayjs().unix() - lastSendTimer
|
||||
const canSend = duration >= 60
|
||||
if (!canSend) {
|
||||
$helper.toast('请稍后再试')
|
||||
return
|
||||
}
|
||||
// 只有 mobile 非空时才校验。因为部分场景(修改密码),不需要输入手机
|
||||
if (mobile && !test.mobile(mobile)) {
|
||||
$helper.toast('手机号码格式不正确')
|
||||
return
|
||||
}
|
||||
|
||||
// 发送验证码 + 更新上次发送验证码时间
|
||||
let scene = -1
|
||||
switch (event) {
|
||||
case 'resetPassword':
|
||||
scene = 4
|
||||
break
|
||||
case 'changePassword':
|
||||
scene = 3
|
||||
break
|
||||
case 'changeMobile':
|
||||
scene = 2
|
||||
break
|
||||
case 'smsLogin':
|
||||
scene = 1
|
||||
break
|
||||
}
|
||||
|
||||
AuthUtil.sendSmsCode(mobile, scene).then((res) => {
|
||||
// if (res.code === 0) {
|
||||
// modalStore.lastTimer[event] = dayjs().unix()
|
||||
// }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,27 +133,27 @@ export function getSmsCode(event, mobile) {
|
|||
* @returns {Type}
|
||||
*/
|
||||
export function getSmsTimer(event) {
|
||||
const modalStore = $store('modal')
|
||||
const lastSendTimer = modalStore.lastTimer[event]
|
||||
const modalStore = $store('modal')
|
||||
const lastSendTimer = modalStore.lastTimer[event]
|
||||
|
||||
if (typeof lastSendTimer === 'undefined') {
|
||||
$helper.toast('短信发送事件错误')
|
||||
return
|
||||
}
|
||||
if (typeof lastSendTimer === 'undefined') {
|
||||
$helper.toast('短信发送事件错误')
|
||||
return
|
||||
}
|
||||
|
||||
const duration = ref(dayjs().unix() - lastSendTimer - 60)
|
||||
const canSend = duration.value >= 0
|
||||
const duration = ref(dayjs().unix() - lastSendTimer - 60)
|
||||
const canSend = duration.value >= 0
|
||||
|
||||
if (canSend) {
|
||||
return '获取验证码'
|
||||
}
|
||||
if (canSend) {
|
||||
return '获取验证码'
|
||||
}
|
||||
|
||||
if (!canSend) {
|
||||
setTimeout(() => {
|
||||
duration.value++
|
||||
}, 1000)
|
||||
return -duration.value.toString() + ' 秒'
|
||||
}
|
||||
if (!canSend) {
|
||||
setTimeout(() => {
|
||||
duration.value++
|
||||
}, 1000)
|
||||
return -duration.value.toString() + ' 秒'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,11 +163,11 @@ export function getSmsTimer(event) {
|
|||
* @returns {Type}
|
||||
*/
|
||||
export function saveAdvHistory(adv) {
|
||||
const modal = $store('modal')
|
||||
const modal = $store('modal')
|
||||
|
||||
modal.$patch((state) => {
|
||||
if (!state.advHistory.includes(adv.imgUrl)) {
|
||||
state.advHistory.push(adv.imgUrl)
|
||||
}
|
||||
})
|
||||
modal.$patch((state) => {
|
||||
if (!state.advHistory.includes(adv.imgUrl)) {
|
||||
state.advHistory.push(adv.imgUrl)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -10,26 +10,26 @@ import $store from '@/peach/store'
|
|||
import AuthUtil from '@/peach/api/member/auth'
|
||||
|
||||
const options = {
|
||||
// 显示操作成功消息 默认不显示
|
||||
showSuccess: false,
|
||||
// 成功提醒 默认使用后端返回值
|
||||
successMsg: '',
|
||||
// 显示失败消息 默认显示
|
||||
showError: true,
|
||||
// 失败提醒 默认使用后端返回信息
|
||||
errorMsg: '',
|
||||
// 显示请求时loading模态框 默认显示
|
||||
showLoading: true,
|
||||
// loading提醒文字
|
||||
loadingMsg: '加载中',
|
||||
// 需要授权才能请求 默认放开
|
||||
auth: true,
|
||||
// 显示操作成功消息 默认不显示
|
||||
showSuccess: false,
|
||||
// 成功提醒 默认使用后端返回值
|
||||
successMsg: '',
|
||||
// 显示失败消息 默认显示
|
||||
showError: true,
|
||||
// 失败提醒 默认使用后端返回信息
|
||||
errorMsg: '',
|
||||
// 显示请求时loading模态框 默认显示
|
||||
showLoading: true,
|
||||
// loading提醒文字
|
||||
loadingMsg: '加载中',
|
||||
// 需要授权才能请求 默认放开
|
||||
auth: true,
|
||||
}
|
||||
|
||||
// Loading全局实例
|
||||
let LoadingInstance = {
|
||||
target: null,
|
||||
count: 0,
|
||||
target: null,
|
||||
count: 0,
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,20 +39,20 @@ let LoadingInstance = {
|
|||
* @returns {Type}
|
||||
*/
|
||||
function closeLoading() {
|
||||
if (LoadingInstance.count > 0) LoadingInstance.count--
|
||||
if (LoadingInstance.count === 0) uni.hideLoading()
|
||||
if (LoadingInstance.count > 0) LoadingInstance.count--
|
||||
if (LoadingInstance.count === 0) uni.hideLoading()
|
||||
}
|
||||
|
||||
// 请求实例
|
||||
const http = new Request({
|
||||
baseURL: baseUrl + apiPath,
|
||||
timeout: 8000,
|
||||
method: 'GET',
|
||||
header: {
|
||||
Accept: 'text/json',
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
},
|
||||
custom: options,
|
||||
baseURL: baseUrl + apiPath,
|
||||
timeout: 8000,
|
||||
method: 'GET',
|
||||
header: {
|
||||
Accept: 'text/json',
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
},
|
||||
custom: options,
|
||||
})
|
||||
|
||||
/**
|
||||
|
@ -63,39 +63,40 @@ const http = new Request({
|
|||
*/
|
||||
|
||||
http.interceptors.request.use(
|
||||
(config) => {
|
||||
// 自定义处理【auth 授权】:必须登录的接口,否则提示登录
|
||||
if (config.custom.auth && !$store('user').isLogin) {
|
||||
// 处理登录
|
||||
peach.$router.go('/pages/index/login')
|
||||
return Promise.reject()
|
||||
}
|
||||
|
||||
// 自定义处理【loading 加载中】:如果需要显示 loading,则显示 loading
|
||||
if (config.custom.showLoading) {
|
||||
LoadingInstance.count++
|
||||
LoadingInstance.count === 1 &&
|
||||
uni.showLoading({
|
||||
title: config.custom.loadingMsg,
|
||||
mask: true,
|
||||
fail: () => {
|
||||
uni.hideLoading()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 增加 token 令牌、terminal 终端、tenant 租户的请求头
|
||||
const token = getAccessToken()
|
||||
if (token) {
|
||||
config.header['Authorization'] = token
|
||||
}
|
||||
config.header['Accept'] = '*/*'
|
||||
config.header['tenant-id'] = '1'
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error)
|
||||
(config) => {
|
||||
console.log(config)
|
||||
// 自定义处理【auth 授权】:必须登录的接口,否则提示登录
|
||||
if (config.custom.auth && !$store('user').isLogin) {
|
||||
// 处理登录
|
||||
peach.$router.go('/pages/index/login')
|
||||
return Promise.reject()
|
||||
}
|
||||
|
||||
// 自定义处理【loading 加载中】:如果需要显示 loading,则显示 loading
|
||||
if (config.custom.showLoading) {
|
||||
LoadingInstance.count++
|
||||
LoadingInstance.count === 1 &&
|
||||
uni.showLoading({
|
||||
title: config.custom.loadingMsg,
|
||||
mask: true,
|
||||
fail: () => {
|
||||
uni.hideLoading()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 增加 token 令牌、terminal 终端、tenant 租户的请求头
|
||||
const token = getAccessToken()
|
||||
if (token) {
|
||||
config.header['Authorization'] = token
|
||||
}
|
||||
config.header['Accept'] = '*/*'
|
||||
config.header['tenant-id'] = '1'
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
|
@ -105,194 +106,189 @@ http.interceptors.request.use(
|
|||
* @returns {Type}
|
||||
*/
|
||||
http.interceptors.response.use(
|
||||
(response) => {
|
||||
// console.log('response', response)
|
||||
// 约定:如果是 /auth/ 下的 URL 地址,并且返回了 accessToken 说明是登录相关的接口,则自动设置登陆令牌
|
||||
if (response.config.url.indexOf('/member/auth/') >= 0 && response.data?.data?.accessToken) {
|
||||
$store('user').setToken(response.data.data.accessToken, response.data.data.refreshToken)
|
||||
}
|
||||
|
||||
// 自定处理【loading 加载中】:如果需要显示 loading,则关闭 loading
|
||||
response.config.custom.showLoading && closeLoading()
|
||||
|
||||
// 自定义处理【error 错误提示】:如果需要显示错误提示,则显示错误提示
|
||||
if (response.data.code !== 0) {
|
||||
// 特殊:如果 401 错误码,则跳转到登录页 or 刷新令牌
|
||||
if (response.data.code === 401) {
|
||||
return refreshToken(response.config)
|
||||
}
|
||||
|
||||
// 错误提示
|
||||
if (response.config.custom.showError) {
|
||||
uni.showToast({
|
||||
title: response.data.msg || '服务器开小差啦,请稍后再试~',
|
||||
icon: 'none',
|
||||
mask: true,
|
||||
})
|
||||
return Promise.reject(false)
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义处理【showSuccess 成功提示】:如果需要显示成功提示,则显示成功提示
|
||||
if (
|
||||
response.config.custom.showSuccess &&
|
||||
response.config.custom.successMsg !== '' &&
|
||||
response.data.code === 0
|
||||
) {
|
||||
uni.showToast({
|
||||
title: response.config.custom.successMsg,
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
|
||||
// 返回结果:包括 code + data + msg
|
||||
return Promise.resolve(response.data)
|
||||
},
|
||||
(error) => {
|
||||
console.log('error', error)
|
||||
const userStore = $store('user')
|
||||
const isLogin = userStore.isLogin
|
||||
let errorMessage = '网络请求出错'
|
||||
if (error !== undefined) {
|
||||
switch (error.statusCode) {
|
||||
case 400:
|
||||
errorMessage = '请求错误'
|
||||
break
|
||||
case 401:
|
||||
errorMessage = isLogin ? '您的登陆已过期' : '请先登录'
|
||||
// 正常情况下,后端不会返回 401 错误,所以这里不处理 handleAuthorized
|
||||
break
|
||||
case 403:
|
||||
errorMessage = '拒绝访问'
|
||||
break
|
||||
case 404:
|
||||
errorMessage = '请求出错'
|
||||
break
|
||||
case 408:
|
||||
errorMessage = '请求超时'
|
||||
break
|
||||
case 429:
|
||||
errorMessage = '请求频繁, 请稍后再访问'
|
||||
break
|
||||
case 500:
|
||||
errorMessage = '服务器开小差啦,请稍后再试~'
|
||||
break
|
||||
case 501:
|
||||
errorMessage = '服务未实现'
|
||||
break
|
||||
case 502:
|
||||
errorMessage = '网络错误'
|
||||
break
|
||||
case 503:
|
||||
errorMessage = '服务不可用'
|
||||
break
|
||||
case 504:
|
||||
errorMessage = '网络超时'
|
||||
break
|
||||
case 505:
|
||||
errorMessage = 'HTTP 版本不受支持'
|
||||
break
|
||||
}
|
||||
if (error.errMsg.includes('timeout')) errorMessage = '请求超时'
|
||||
// #ifdef H5
|
||||
if (error.errMsg.includes('Network'))
|
||||
errorMessage = window.navigator.onLine ? '服务器异常' : '请检查您的网络连接'
|
||||
// #endif
|
||||
}
|
||||
|
||||
if (error && error.config) {
|
||||
if (error.config.custom.showError === true) {
|
||||
uni.showToast({
|
||||
title: error.data?.msg || errorMessage,
|
||||
icon: 'none',
|
||||
mask: true,
|
||||
})
|
||||
}
|
||||
error.config.custom.showLoading && closeLoading()
|
||||
}
|
||||
|
||||
return Promise.reject(false)
|
||||
(response) => {
|
||||
// console.log('response', response)
|
||||
// 约定:如果是 /auth/ 下的 URL 地址,并且返回了 accessToken 说明是登录相关的接口,则自动设置登陆令牌
|
||||
if (response.config.url.indexOf('/member/auth/') >= 0 && response.data?.data?.accessToken) {
|
||||
$store('user').setToken(response.data.data.accessToken, response.data.data.refreshToken)
|
||||
}
|
||||
|
||||
// 自定处理【loading 加载中】:如果需要显示 loading,则关闭 loading
|
||||
response.config.custom.showLoading && closeLoading()
|
||||
|
||||
// 自定义处理【error 错误提示】:如果需要显示错误提示,则显示错误提示
|
||||
if (response.data.code !== 0) {
|
||||
// 特殊:如果 401 错误码,则跳转到登录页 or 刷新令牌
|
||||
if (response.data.code === 401) {
|
||||
return refreshToken(response.config)
|
||||
}
|
||||
|
||||
// 错误提示
|
||||
if (response.config.custom.showError) {
|
||||
uni.showToast({
|
||||
title: response.data.msg || '服务器开小差啦,请稍后再试~',
|
||||
icon: 'none',
|
||||
mask: true,
|
||||
})
|
||||
return Promise.reject(false)
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义处理【showSuccess 成功提示】:如果需要显示成功提示,则显示成功提示
|
||||
if (response.config.custom.showSuccess && response.config.custom.successMsg !== '' && response.data.code === 0) {
|
||||
uni.showToast({
|
||||
title: response.config.custom.successMsg,
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
|
||||
// 返回结果:包括 code + data + msg
|
||||
return Promise.resolve(response.data)
|
||||
},
|
||||
(error) => {
|
||||
console.log('error', error)
|
||||
const userStore = $store('user')
|
||||
const isLogin = userStore.isLogin
|
||||
let errorMessage = '网络请求出错'
|
||||
if (error !== undefined) {
|
||||
switch (error.statusCode) {
|
||||
case 400:
|
||||
errorMessage = '请求错误'
|
||||
break
|
||||
case 401:
|
||||
errorMessage = isLogin ? '您的登陆已过期' : '请先登录'
|
||||
// 正常情况下,后端不会返回 401 错误,所以这里不处理 handleAuthorized
|
||||
break
|
||||
case 403:
|
||||
errorMessage = '拒绝访问'
|
||||
break
|
||||
case 404:
|
||||
errorMessage = '请求出错'
|
||||
break
|
||||
case 408:
|
||||
errorMessage = '请求超时'
|
||||
break
|
||||
case 429:
|
||||
errorMessage = '请求频繁, 请稍后再访问'
|
||||
break
|
||||
case 500:
|
||||
errorMessage = '服务器开小差啦,请稍后再试~'
|
||||
break
|
||||
case 501:
|
||||
errorMessage = '服务未实现'
|
||||
break
|
||||
case 502:
|
||||
errorMessage = '网络错误'
|
||||
break
|
||||
case 503:
|
||||
errorMessage = '服务不可用'
|
||||
break
|
||||
case 504:
|
||||
errorMessage = '网络超时'
|
||||
break
|
||||
case 505:
|
||||
errorMessage = 'HTTP 版本不受支持'
|
||||
break
|
||||
}
|
||||
if (error.errMsg.includes('timeout')) errorMessage = '请求超时'
|
||||
// #ifdef H5
|
||||
if (error.errMsg.includes('Network')) errorMessage = window.navigator.onLine ? '服务器异常' : '请检查您的网络连接'
|
||||
// #endif
|
||||
}
|
||||
|
||||
if (error && error.config) {
|
||||
if (error.config.custom.showError === true) {
|
||||
uni.showToast({
|
||||
title: error.data?.msg || errorMessage,
|
||||
icon: 'none',
|
||||
mask: true,
|
||||
})
|
||||
}
|
||||
error.config.custom.showLoading && closeLoading()
|
||||
}
|
||||
|
||||
return Promise.reject(false)
|
||||
}
|
||||
)
|
||||
|
||||
let requestList = [] // 请求队列
|
||||
let isRefreshToken = false // 是否正在刷新中
|
||||
const refreshToken = async (config) => {
|
||||
// 如果当前已经是 refresh-token 的 URL 地址,并且还是 401 错误,说明是刷新令牌失败了,直接返回 Promise.reject(error)
|
||||
if (config.url.indexOf('/member/auth/refresh-token') >= 0) {
|
||||
return Promise.reject('error')
|
||||
}
|
||||
// 如果当前已经是 refresh-token 的 URL 地址,并且还是 401 错误,说明是刷新令牌失败了,直接返回 Promise.reject(error)
|
||||
if (config.url.indexOf('/member/auth/refresh-token') >= 0) {
|
||||
return Promise.reject('error')
|
||||
}
|
||||
|
||||
// 如果未认证,并且未进行刷新令牌,说明可能是访问令牌过期了
|
||||
if (!isRefreshToken) {
|
||||
isRefreshToken = true
|
||||
// 1. 如果获取不到刷新令牌,则只能执行登出操作
|
||||
const refreshToken = getRefreshToken()
|
||||
if (!refreshToken) {
|
||||
return handleAuthorized()
|
||||
}
|
||||
// 2. 进行刷新访问令牌
|
||||
try {
|
||||
const refreshTokenResult = await AuthUtil.refreshToken(refreshToken)
|
||||
if (refreshTokenResult.code !== 0) {
|
||||
// 如果刷新不成功,直接抛出 e 触发 2.2 的逻辑
|
||||
// noinspection ExceptionCaughtLocallyJS
|
||||
throw new Error('刷新令牌失败')
|
||||
}
|
||||
// 2.1 刷新成功,则回放队列的请求 + 当前请求
|
||||
config.header.Authorization = 'Bearer ' + getAccessToken()
|
||||
requestList.forEach((cb) => {
|
||||
cb()
|
||||
})
|
||||
requestList = []
|
||||
return request(config)
|
||||
} catch (e) {
|
||||
// 为什么需要 catch 异常呢?刷新失败时,请求因为 Promise.reject 触发异常。
|
||||
// 2.2 刷新失败,只回放队列的请求
|
||||
requestList.forEach((cb) => {
|
||||
cb()
|
||||
})
|
||||
// 提示是否要登出。即不回放当前请求!不然会形成递归
|
||||
return handleAuthorized()
|
||||
} finally {
|
||||
requestList = []
|
||||
isRefreshToken = false
|
||||
}
|
||||
} else {
|
||||
// 添加到队列,等待刷新获取到新的令牌
|
||||
return new Promise((resolve) => {
|
||||
requestList.push(() => {
|
||||
config.header.Authorization = 'Bearer ' + getAccessToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||
resolve(request(config))
|
||||
})
|
||||
})
|
||||
// 如果未认证,并且未进行刷新令牌,说明可能是访问令牌过期了
|
||||
if (!isRefreshToken) {
|
||||
isRefreshToken = true
|
||||
// 1. 如果获取不到刷新令牌,则只能执行登出操作
|
||||
const refreshToken = getRefreshToken()
|
||||
if (!refreshToken) {
|
||||
return handleAuthorized()
|
||||
}
|
||||
// 2. 进行刷新访问令牌
|
||||
try {
|
||||
const refreshTokenResult = await AuthUtil.refreshToken(refreshToken)
|
||||
if (refreshTokenResult.code !== 0) {
|
||||
// 如果刷新不成功,直接抛出 e 触发 2.2 的逻辑
|
||||
// noinspection ExceptionCaughtLocallyJS
|
||||
throw new Error('刷新令牌失败')
|
||||
}
|
||||
// 2.1 刷新成功,则回放队列的请求 + 当前请求
|
||||
config.header.Authorization = 'Bearer ' + getAccessToken()
|
||||
requestList.forEach((cb) => {
|
||||
cb()
|
||||
})
|
||||
requestList = []
|
||||
return request(config)
|
||||
} catch (e) {
|
||||
// 为什么需要 catch 异常呢?刷新失败时,请求因为 Promise.reject 触发异常。
|
||||
// 2.2 刷新失败,只回放队列的请求
|
||||
requestList.forEach((cb) => {
|
||||
cb()
|
||||
})
|
||||
// 提示是否要登出。即不回放当前请求!不然会形成递归
|
||||
return handleAuthorized()
|
||||
} finally {
|
||||
requestList = []
|
||||
isRefreshToken = false
|
||||
}
|
||||
} else {
|
||||
// 添加到队列,等待刷新获取到新的令牌
|
||||
return new Promise((resolve) => {
|
||||
requestList.push(() => {
|
||||
config.header.Authorization = 'Bearer ' + getAccessToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||
resolve(request(config))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/** 处理 401 未登陆的错误 */
|
||||
const handleAuthorized = () => {
|
||||
const userStore = $store('user')
|
||||
userStore.logOut()
|
||||
peach.$router.go('/pages/index/login')
|
||||
// 登录超时
|
||||
return Promise.reject({
|
||||
code: 401,
|
||||
msg: userStore.isLogin ? '您的登陆已过期' : '请先登录',
|
||||
})
|
||||
const userStore = $store('user')
|
||||
userStore.logOut()
|
||||
peach.$router.go('/pages/index/login')
|
||||
// 登录超时
|
||||
return Promise.reject({
|
||||
code: 401,
|
||||
msg: userStore.isLogin ? '您的登陆已过期' : '请先登录',
|
||||
})
|
||||
}
|
||||
|
||||
/** 获得访问令牌 */
|
||||
const getAccessToken = () => {
|
||||
return uni.getStorageSync('token')
|
||||
return uni.getStorageSync('token')
|
||||
}
|
||||
|
||||
/** 获得刷新令牌 */
|
||||
const getRefreshToken = () => {
|
||||
return uni.getStorageSync('refresh-token')
|
||||
return uni.getStorageSync('refresh-token')
|
||||
}
|
||||
|
||||
const request = (config) => {
|
||||
return http.middleware(config)
|
||||
return http.middleware(config)
|
||||
}
|
||||
|
||||
export default request
|
||||
|
|
|
@ -1,47 +1,47 @@
|
|||
<template>
|
||||
<view class="page-app" :class="['theme-' + sys.mode, 'main-' + sys.theme, 'font-' + sys.fontSize]">
|
||||
<view class="page-main" :style="[bgMain]">
|
||||
<!-- 顶部导航栏-情况1:默认通用顶部导航栏 -->
|
||||
<pb-navbar
|
||||
v-if="navbar === 'normal'"
|
||||
:title="title"
|
||||
:leftIcon="leftIcon"
|
||||
statusBar
|
||||
:color="color"
|
||||
:tools="tools"
|
||||
:opacityBgUi="opacityBgUi"
|
||||
@search="(e) => emits('search', e)"
|
||||
:defaultSearch="defaultSearch"
|
||||
/>
|
||||
<view class="page-body" :style="[bgBody]">
|
||||
<!-- 顶部导航栏-情况2:沉浸式头部 -->
|
||||
<pb-inner-navbar
|
||||
v-if="navbar === 'inner'"
|
||||
:iconColor="iconColor"
|
||||
:color="color"
|
||||
:right="props.right"
|
||||
:title="title"
|
||||
:leftIcon="leftIcon"
|
||||
/>
|
||||
<view v-if="navbar === 'inner'" :style="[{ paddingTop: peach.$platform.navBar + 'px' }]"></view>
|
||||
<view class="page-app" :class="['theme-' + sys.mode, 'main-' + sys.theme, 'font-' + sys.fontSize]">
|
||||
<view class="page-main" :style="[bgMain]">
|
||||
<!-- 顶部导航栏-情况1:默认通用顶部导航栏 -->
|
||||
<pb-navbar
|
||||
v-if="navbar === 'normal'"
|
||||
:title="title"
|
||||
:leftIcon="leftIcon"
|
||||
statusBar
|
||||
:color="color"
|
||||
:tools="tools"
|
||||
:opacityBgUi="opacityBgUi"
|
||||
@search="(e) => emits('search', e)"
|
||||
:defaultSearch="defaultSearch"
|
||||
/>
|
||||
<view class="page-body" :style="[bgBody]">
|
||||
<!-- 顶部导航栏-情况2:沉浸式头部 -->
|
||||
<pb-inner-navbar
|
||||
v-if="navbar === 'inner'"
|
||||
:iconColor="iconColor"
|
||||
:color="color"
|
||||
:right="props.right"
|
||||
:title="title"
|
||||
:leftIcon="leftIcon"
|
||||
/>
|
||||
<view v-if="navbar === 'inner'" :style="[{ paddingTop: peach.$platform.navBar + 'px' }]"></view>
|
||||
|
||||
<!-- 页面内容插槽 -->
|
||||
<slot />
|
||||
<!-- 页面内容插槽 -->
|
||||
<slot />
|
||||
|
||||
<!-- 底部导航 -->
|
||||
<pb-tabbar v-if="tabbar !== ''" :path="tabbar" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="page-modal">
|
||||
<!-- 全局授权弹窗 -->
|
||||
<!-- <p-auth-modal /> -->
|
||||
<!-- 全局分享弹窗 -->
|
||||
<!-- <p-share-modal :shareInfo="shareInfo" /> -->
|
||||
<!-- 全局快捷入口 -->
|
||||
<p-menu-tools />
|
||||
</view>
|
||||
<!-- 底部导航 -->
|
||||
<pb-tabbar v-if="tabbar !== ''" :path="tabbar" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="page-modal">
|
||||
<!-- 全局授权弹窗 -->
|
||||
<!-- <p-auth-modal /> -->
|
||||
<!-- 全局分享弹窗 -->
|
||||
<!-- <p-share-modal :shareInfo="shareInfo" /> -->
|
||||
<!-- 全局快捷入口 -->
|
||||
<p-menu-tools />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
|
@ -66,70 +66,70 @@ import { onShareAppMessage } from '@dcloudio/uni-app'
|
|||
// #endif
|
||||
|
||||
const props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
leftIcon: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
navbar: {
|
||||
type: String,
|
||||
default: 'normal',
|
||||
},
|
||||
opacityBgUi: {
|
||||
type: String,
|
||||
default: 'bg-white',
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
tools: {
|
||||
type: String,
|
||||
default: 'title',
|
||||
},
|
||||
bgStyle: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
src: '',
|
||||
color: 'var(--ui-BG-1)',
|
||||
}),
|
||||
},
|
||||
tabbar: {
|
||||
type: [String, Boolean],
|
||||
default: '',
|
||||
},
|
||||
onShareAppMessage: {
|
||||
type: [Boolean, Object],
|
||||
default: true,
|
||||
},
|
||||
leftWidth: {
|
||||
type: [Number, String],
|
||||
default: 100,
|
||||
},
|
||||
rightWidth: {
|
||||
type: [Number, String],
|
||||
default: 100,
|
||||
},
|
||||
defaultSearch: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
//展示返回按钮
|
||||
showLeftButton: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
iconColor: {
|
||||
type: String,
|
||||
default: '#000',
|
||||
},
|
||||
right: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
leftIcon: {
|
||||
type: String,
|
||||
default: 'leftIcon',
|
||||
},
|
||||
navbar: {
|
||||
type: String,
|
||||
default: 'normal',
|
||||
},
|
||||
opacityBgUi: {
|
||||
type: String,
|
||||
default: 'bg-white',
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
tools: {
|
||||
type: String,
|
||||
default: 'title',
|
||||
},
|
||||
bgStyle: {
|
||||
type: Object,
|
||||
default: () => ({
|
||||
src: '',
|
||||
color: 'var(--ui-BG-1)',
|
||||
}),
|
||||
},
|
||||
tabbar: {
|
||||
type: [String, Boolean],
|
||||
default: '',
|
||||
},
|
||||
onShareAppMessage: {
|
||||
type: [Boolean, Object],
|
||||
default: true,
|
||||
},
|
||||
leftWidth: {
|
||||
type: [Number, String],
|
||||
default: 100,
|
||||
},
|
||||
rightWidth: {
|
||||
type: [Number, String],
|
||||
default: 100,
|
||||
},
|
||||
defaultSearch: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
//展示返回按钮
|
||||
showLeftButton: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
iconColor: {
|
||||
type: String,
|
||||
default: '#000',
|
||||
},
|
||||
right: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
})
|
||||
const emits = defineEmits(['search'])
|
||||
|
||||
|
@ -141,102 +141,102 @@ const sys = computed(() => sysStore)
|
|||
|
||||
// 导航栏模式(因为有自定义导航栏 需要计算)
|
||||
const navbarMode = computed(() => {
|
||||
if (props.navbar === 'normal') {
|
||||
return 'normal'
|
||||
}
|
||||
return 'inner'
|
||||
if (props.navbar === 'normal') {
|
||||
return 'normal'
|
||||
}
|
||||
return 'inner'
|
||||
})
|
||||
|
||||
// 背景1
|
||||
const bgMain = computed(() => {
|
||||
if (navbarMode.value === 'inner') {
|
||||
return {
|
||||
background: `${props.bgStyle.backgroundColor} url(${peach.$url.static(
|
||||
props.bgStyle.backgroundImage,
|
||||
props.bgStyle.imageType
|
||||
)}) no-repeat top center / 100% ${props.bgStyle.height || 'auto'}`,
|
||||
}
|
||||
if (navbarMode.value === 'inner') {
|
||||
return {
|
||||
background: `${props.bgStyle.backgroundColor} url(${peach.$url.static(
|
||||
props.bgStyle.backgroundImage,
|
||||
props.bgStyle.imageType
|
||||
)}) no-repeat top center / 100% ${props.bgStyle.height || 'auto'}`,
|
||||
}
|
||||
return {}
|
||||
}
|
||||
return {}
|
||||
})
|
||||
|
||||
// 背景2
|
||||
const bgBody = computed(() => {
|
||||
if (navbarMode.value === 'normal') {
|
||||
return {
|
||||
background: `${props.bgStyle.backgroundColor} url(${peach.$url.static(
|
||||
props.bgStyle.backgroundImage,
|
||||
props.bgStyle.imageType
|
||||
)}) no-repeat top center / 100% auto`,
|
||||
}
|
||||
if (navbarMode.value === 'normal') {
|
||||
return {
|
||||
background: `${props.bgStyle.backgroundColor} url(${peach.$url.static(
|
||||
props.bgStyle.backgroundImage,
|
||||
props.bgStyle.imageType
|
||||
)}) no-repeat top center / 100% auto`,
|
||||
}
|
||||
return {}
|
||||
}
|
||||
return {}
|
||||
})
|
||||
|
||||
// 分享信息
|
||||
const shareInfo = computed(() => {
|
||||
if (props.onShareAppMessage === true) {
|
||||
return peach.$platform.share.getShareInfo()
|
||||
} else {
|
||||
if (!isEmpty(props.onShareAppMessage)) {
|
||||
// peach.$platform.share.updateShareInfo(props.onShareAppMessage)
|
||||
return props.onShareAppMessage
|
||||
}
|
||||
if (props.onShareAppMessage === true) {
|
||||
return peach.$platform.share.getShareInfo()
|
||||
} else {
|
||||
if (!isEmpty(props.onShareAppMessage)) {
|
||||
// peach.$platform.share.updateShareInfo(props.onShareAppMessage)
|
||||
return props.onShareAppMessage
|
||||
}
|
||||
return {}
|
||||
}
|
||||
return {}
|
||||
})
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
// 微信小程序分享
|
||||
onShareAppMessage(() => {
|
||||
return {
|
||||
title: shareInfo.value.title,
|
||||
path: shareInfo.value.path,
|
||||
imageUrl: shareInfo.value.image,
|
||||
}
|
||||
return {
|
||||
title: shareInfo.value.title,
|
||||
path: shareInfo.value.path,
|
||||
imageUrl: shareInfo.value.image,
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
|
||||
onShow(() => {
|
||||
if (!isEmpty(shareInfo.value)) {
|
||||
// peach.$platform.share.updateShareInfo(shareInfo.value)
|
||||
}
|
||||
if (!isEmpty(shareInfo.value)) {
|
||||
// peach.$platform.share.updateShareInfo(shareInfo.value)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page-app {
|
||||
position: relative;
|
||||
color: var(--ui-TC);
|
||||
background-color: var(--ui-BG-1) !important;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
position: relative;
|
||||
color: var(--ui-TC);
|
||||
background-color: var(--ui-BG-1) !important;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
|
||||
.page-main {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
min-height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.page-main {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
width: 100%;
|
||||
min-height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.page-body {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.page-img {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 0;
|
||||
}
|
||||
.page-body {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.page-img {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -1,80 +1,76 @@
|
|||
<!-- 自定义导航栏 -->
|
||||
<template>
|
||||
<view class="uni-navbar" :class="{ 'uni-dark': dark }">
|
||||
<view
|
||||
:class="{
|
||||
'uni-navbar--fixed': fixed,
|
||||
'uni-navbar--shadow': shadow,
|
||||
'uni-navbar--border': border,
|
||||
}"
|
||||
class="uni-navbar__content"
|
||||
>
|
||||
<view class="fixed-bg" :class="[opacity ? '' : opacityBgUi]"></view>
|
||||
<pb-status-bar v-if="statusBar" />
|
||||
<view
|
||||
:style="{
|
||||
color: themeColor,
|
||||
height: navbarHeight,
|
||||
background: backgroundColor,
|
||||
}"
|
||||
class="uni-navbar__header"
|
||||
>
|
||||
<view class="uni-navbar__header-btns uni-navbar__header-btns-left" :style="{ width: leftIconWidth }">
|
||||
<slot name="left">
|
||||
<view class="uni-navbar__content_view" v-if="leftIcon.length > 0">
|
||||
<view class="icon-box ss-flex">
|
||||
<view class="icon-button icon-button-left ss-flex ss-row-center" @tap="onClickLeft">
|
||||
<text class="sicon-back" v-if="hasHistory" />
|
||||
<text class="sicon-home" v-else />
|
||||
</view>
|
||||
<view class="line"></view>
|
||||
<view class="icon-button icon-button-right ss-flex ss-row-center" @tap="showMenuTools">
|
||||
<text class="sicon-more" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
:class="{ 'uni-navbar-btn-icon-left': !leftIcon.length > 0 }"
|
||||
class="uni-navbar-btn-text"
|
||||
v-if="
|
||||
titleAlign === 'left' &&
|
||||
title.length &&
|
||||
peach.$platform.name !== 'WechatOfficialAccount'
|
||||
"
|
||||
>
|
||||
<text :style="{ color: themeColor, fontSize: '18px' }">{{ title }}</text>
|
||||
</view>
|
||||
</slot>
|
||||
<view class="uni-navbar" :class="{ 'uni-dark': dark }">
|
||||
<view
|
||||
:class="{
|
||||
'uni-navbar--fixed': fixed,
|
||||
'uni-navbar--shadow': shadow,
|
||||
'uni-navbar--border': border,
|
||||
}"
|
||||
class="uni-navbar__content"
|
||||
>
|
||||
<view class="fixed-bg" :class="[opacity ? '' : opacityBgUi]"></view>
|
||||
<pb-status-bar v-if="statusBar" />
|
||||
<view
|
||||
:style="{
|
||||
color: themeColor,
|
||||
height: navbarHeight,
|
||||
background: backgroundColor,
|
||||
}"
|
||||
class="uni-navbar__header"
|
||||
>
|
||||
<view class="uni-navbar__header-btns uni-navbar__header-btns-left" :style="{ width: leftIconWidth }">
|
||||
<slot name="left">
|
||||
<view class="uni-navbar__content_view" v-if="leftIcon.length > 0">
|
||||
<view class="icon-box ss-flex">
|
||||
<view class="icon-button icon-button-left ss-flex ss-row-center" @tap="onClickLeft">
|
||||
<text class="sicon-back" v-if="hasHistory" />
|
||||
<text class="sicon-home" v-else />
|
||||
</view>
|
||||
<view v-if="tools === 'search'" class="ss-flex-1">
|
||||
<slot name="center">
|
||||
<uni-search-bar
|
||||
class="ss-flex-1 search-box"
|
||||
:radius="20"
|
||||
placeholder="请输入关键词"
|
||||
cancelButton="none"
|
||||
v-model="searchModel"
|
||||
@confirm="onSearch"
|
||||
/>
|
||||
</slot>
|
||||
</view>
|
||||
<view v-else class="uni-navbar__header-container" @tap="onClickTitle">
|
||||
<slot name="center">
|
||||
<view
|
||||
v-if="tools === 'title' && titleAlign === 'center' && title.length"
|
||||
class="uni-navbar__header-container-inner"
|
||||
>
|
||||
<text :style="{ color: themeColor, fontSize: '36rpx' }" class="ss-line-1">{{ title }}</text>
|
||||
</view>
|
||||
</slot>
|
||||
<view class="line"></view>
|
||||
<view class="icon-button icon-button-right ss-flex ss-row-center" @tap="showMenuTools">
|
||||
<text class="sicon-more" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
:class="{ 'uni-navbar-btn-icon-left': !leftIcon.length > 0 }"
|
||||
class="uni-navbar-btn-text"
|
||||
v-if="titleAlign === 'left' && title.length && peach.$platform.name !== 'WechatOfficialAccount'"
|
||||
>
|
||||
<text :style="{ color: themeColor, fontSize: '18px' }">{{ title }}</text>
|
||||
</view>
|
||||
</slot>
|
||||
</view>
|
||||
<view class="uni-navbar__placeholder" v-if="placeholder">
|
||||
<pb-status-bar v-if="statusBar" />
|
||||
<view class="uni-navbar__placeholder-view" :style="{ height: navbarHeight }" />
|
||||
<view v-if="tools === 'search'" class="ss-flex-1">
|
||||
<slot name="center">
|
||||
<uni-search-bar
|
||||
class="ss-flex-1 search-box"
|
||||
:radius="20"
|
||||
placeholder="请输入关键词"
|
||||
cancelButton="none"
|
||||
v-model="searchModel"
|
||||
@confirm="onSearch"
|
||||
/>
|
||||
</slot>
|
||||
</view>
|
||||
<view v-else class="uni-navbar__header-container" @tap="onClickTitle">
|
||||
<slot name="center">
|
||||
<view
|
||||
v-if="tools === 'title' && titleAlign === 'center' && title.length"
|
||||
class="uni-navbar__header-container-inner"
|
||||
>
|
||||
<text :style="{ color: themeColor, fontSize: '36rpx' }" class="ss-line-1">{{ title }}</text>
|
||||
</view>
|
||||
</slot>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="uni-navbar__placeholder" v-if="placeholder">
|
||||
<pb-status-bar v-if="statusBar" />
|
||||
<view class="uni-navbar__placeholder-view" :style="{ height: navbarHeight }" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
|
@ -105,322 +101,322 @@ const getVal = (val) => (typeof val === 'number' ? val + 'px' : val)
|
|||
|
||||
const emits = defineEmits(['clickLeft', 'clickRight', 'clickTitle', 'search'])
|
||||
const props = defineProps({
|
||||
dark: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
modelValue: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
// left | center
|
||||
titleAlign: {
|
||||
type: String,
|
||||
default: 'center',
|
||||
},
|
||||
rightText: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
leftIcon: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
rightIcon: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
fixed: {
|
||||
type: [Boolean, String],
|
||||
default: true,
|
||||
},
|
||||
placeholder: {
|
||||
type: [Boolean, String],
|
||||
default: true,
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
backgroundColor: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
opacity: {
|
||||
type: [Boolean, String],
|
||||
default: false,
|
||||
},
|
||||
opacityBgUi: {
|
||||
type: String,
|
||||
default: 'bg-white',
|
||||
},
|
||||
statusBar: {
|
||||
type: [Boolean, String],
|
||||
default: false,
|
||||
},
|
||||
shadow: {
|
||||
type: [Boolean, String],
|
||||
default: false,
|
||||
},
|
||||
border: {
|
||||
type: [Boolean, String],
|
||||
default: false,
|
||||
},
|
||||
height: {
|
||||
type: [Number, String],
|
||||
default: 44,
|
||||
},
|
||||
leftWidth: {
|
||||
type: [Number, String],
|
||||
default: 80,
|
||||
},
|
||||
rightWidth: {
|
||||
type: [Number, String],
|
||||
default: 0,
|
||||
},
|
||||
tools: {
|
||||
type: String,
|
||||
default: 'title',
|
||||
},
|
||||
defaultSearch: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
dark: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
modelValue: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
// left | center
|
||||
titleAlign: {
|
||||
type: String,
|
||||
default: 'center',
|
||||
},
|
||||
rightText: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
leftIcon: {
|
||||
type: String,
|
||||
default: 'left',
|
||||
},
|
||||
rightIcon: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
fixed: {
|
||||
type: [Boolean, String],
|
||||
default: true,
|
||||
},
|
||||
placeholder: {
|
||||
type: [Boolean, String],
|
||||
default: true,
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
backgroundColor: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
opacity: {
|
||||
type: [Boolean, String],
|
||||
default: false,
|
||||
},
|
||||
opacityBgUi: {
|
||||
type: String,
|
||||
default: 'bg-white',
|
||||
},
|
||||
statusBar: {
|
||||
type: [Boolean, String],
|
||||
default: false,
|
||||
},
|
||||
shadow: {
|
||||
type: [Boolean, String],
|
||||
default: false,
|
||||
},
|
||||
border: {
|
||||
type: [Boolean, String],
|
||||
default: false,
|
||||
},
|
||||
height: {
|
||||
type: [Number, String],
|
||||
default: 44,
|
||||
},
|
||||
leftWidth: {
|
||||
type: [Number, String],
|
||||
default: 80,
|
||||
},
|
||||
rightWidth: {
|
||||
type: [Number, String],
|
||||
default: 0,
|
||||
},
|
||||
tools: {
|
||||
type: String,
|
||||
default: 'title',
|
||||
},
|
||||
defaultSearch: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
})
|
||||
|
||||
const searchModel = computed(() => {
|
||||
return props.defaultSearch
|
||||
return props.defaultSearch
|
||||
})
|
||||
|
||||
const themeColor = computed(() => {
|
||||
if (props.dark) {
|
||||
return props.color ? props.color : '#fff'
|
||||
}
|
||||
return props.color || '#333'
|
||||
if (props.dark) {
|
||||
return props.color ? props.color : '#fff'
|
||||
}
|
||||
return props.color || '#333'
|
||||
})
|
||||
const navbarHeight = computed(() => {
|
||||
return getVal(props.height)
|
||||
return getVal(props.height)
|
||||
})
|
||||
const leftIconWidth = computed(() => {
|
||||
return getVal(props.leftWidth)
|
||||
return getVal(props.leftWidth)
|
||||
})
|
||||
|
||||
function onSearch(e) {
|
||||
emits('search', e.value)
|
||||
emits('search', e.value)
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
if (uni.report && props.title !== '') {
|
||||
uni.report('title', props.title)
|
||||
}
|
||||
if (uni.report && props.title !== '') {
|
||||
uni.report('title', props.title)
|
||||
}
|
||||
})
|
||||
|
||||
const hasHistory = peach.$router.hasHistory()
|
||||
|
||||
function onClickLeft() {
|
||||
if (hasHistory) {
|
||||
peach.$router.back()
|
||||
} else {
|
||||
peach.$router.go('/pages/index/index')
|
||||
}
|
||||
emits('clickLeft')
|
||||
if (hasHistory) {
|
||||
peach.$router.back()
|
||||
} else {
|
||||
peach.$router.go('/pages/index/index')
|
||||
}
|
||||
emits('clickLeft')
|
||||
}
|
||||
function onClickTitle() {
|
||||
emits('clickTitle')
|
||||
emits('clickTitle')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.bg-main {
|
||||
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient)) !important;
|
||||
color: #fff !important;
|
||||
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient)) !important;
|
||||
color: #fff !important;
|
||||
}
|
||||
.icon-box {
|
||||
background: #ffffff;
|
||||
box-shadow: 0px 0px 4rpx rgba(51, 51, 51, 0.08), 0px 4rpx 6rpx 2rpx rgba(102, 102, 102, 0.12);
|
||||
border-radius: 30rpx;
|
||||
width: 134rpx;
|
||||
background: #ffffff;
|
||||
box-shadow: 0px 0px 4rpx rgba(51, 51, 51, 0.08), 0px 4rpx 6rpx 2rpx rgba(102, 102, 102, 0.12);
|
||||
border-radius: 30rpx;
|
||||
width: 134rpx;
|
||||
height: 56rpx;
|
||||
margin-left: 8rpx;
|
||||
.line {
|
||||
width: 2rpx;
|
||||
height: 24rpx;
|
||||
background: #e5e5e7;
|
||||
}
|
||||
.sicon-back {
|
||||
font-size: 32rpx;
|
||||
color: #000;
|
||||
}
|
||||
.sicon-home {
|
||||
font-size: 32rpx;
|
||||
color: #000;
|
||||
}
|
||||
.sicon-more {
|
||||
font-size: 32rpx;
|
||||
color: #000;
|
||||
}
|
||||
.icon-button {
|
||||
width: 67rpx;
|
||||
height: 56rpx;
|
||||
margin-left: 8rpx;
|
||||
.line {
|
||||
width: 2rpx;
|
||||
height: 24rpx;
|
||||
background: #e5e5e7;
|
||||
&-left:hover {
|
||||
background: rgba(0, 0, 0, 0.16);
|
||||
border-radius: 30rpx 0px 0px 30rpx;
|
||||
}
|
||||
.sicon-back {
|
||||
font-size: 32rpx;
|
||||
color: #000;
|
||||
}
|
||||
.sicon-home {
|
||||
font-size: 32rpx;
|
||||
color: #000;
|
||||
}
|
||||
.sicon-more {
|
||||
font-size: 32rpx;
|
||||
color: #000;
|
||||
}
|
||||
.icon-button {
|
||||
width: 67rpx;
|
||||
height: 56rpx;
|
||||
&-left:hover {
|
||||
background: rgba(0, 0, 0, 0.16);
|
||||
border-radius: 30rpx 0px 0px 30rpx;
|
||||
}
|
||||
&-right:hover {
|
||||
background: rgba(0, 0, 0, 0.16);
|
||||
border-radius: 0px 30rpx 30rpx 0px;
|
||||
}
|
||||
&-right:hover {
|
||||
background: rgba(0, 0, 0, 0.16);
|
||||
border-radius: 0px 30rpx 30rpx 0px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$nav-height: 44px;
|
||||
|
||||
.fixed-bg {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.uni-nav-bar-text {
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 34rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 14px;
|
||||
/* #endif */
|
||||
/* #ifdef APP-PLUS */
|
||||
font-size: 34rpx;
|
||||
/* #endif */
|
||||
/* #ifndef APP-PLUS */
|
||||
font-size: 14px;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.uni-nav-bar-right-text {
|
||||
font-size: 12px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.uni-navbar__content {
|
||||
position: relative;
|
||||
background-color: transparent;
|
||||
position: relative;
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.uni-navbar__content_view {
|
||||
// box-sizing: border-box;
|
||||
// box-sizing: border-box;
|
||||
}
|
||||
|
||||
.uni-navbar-btn-text {
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
line-height: 18px;
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
.uni-navbar__header {
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
padding: 0 10px;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
height: $nav-height;
|
||||
font-size: 12px;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
padding: 0 10px;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
height: $nav-height;
|
||||
font-size: 12px;
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.uni-navbar__header-btns {
|
||||
/* #ifndef APP-NVUE */
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
/* #endif */
|
||||
flex-wrap: nowrap;
|
||||
flex-direction: row;
|
||||
min-width: 40rpx;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
/* #ifdef H5 */
|
||||
cursor: pointer;
|
||||
/* #endif */
|
||||
/* #ifndef APP-NVUE */
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
/* #endif */
|
||||
flex-wrap: nowrap;
|
||||
flex-direction: row;
|
||||
min-width: 40rpx;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
/* #ifdef H5 */
|
||||
cursor: pointer;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.uni-navbar__header-btns-left {
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
width: 120rpx;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
width: 120rpx;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.uni-navbar__header-btns-right {
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
flex-direction: row;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
flex-direction: row;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
.uni-navbar__header-container {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translateX(-50%) translateY(-50%);
|
||||
top: 50%;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translateX(-50%) translateY(-50%);
|
||||
top: 50%;
|
||||
}
|
||||
|
||||
.uni-navbar__header-container-inner {
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
flex: 1;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 12px;
|
||||
overflow: hidden;
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
flex: 1;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.uni-navbar__placeholder-view {
|
||||
height: $nav-height;
|
||||
height: $nav-height;
|
||||
}
|
||||
|
||||
.uni-navbar--fixed {
|
||||
position: fixed;
|
||||
z-index: 998;
|
||||
/* #ifdef H5 */
|
||||
left: var(--window-left);
|
||||
right: var(--window-right);
|
||||
/* #endif */
|
||||
/* #ifndef H5 */
|
||||
left: 0;
|
||||
right: 0;
|
||||
/* #endif */
|
||||
position: fixed;
|
||||
z-index: 998;
|
||||
/* #ifdef H5 */
|
||||
left: var(--window-left);
|
||||
right: var(--window-right);
|
||||
/* #endif */
|
||||
/* #ifndef H5 */
|
||||
left: 0;
|
||||
right: 0;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.uni-navbar--shadow {
|
||||
box-shadow: 0 1px 6px #ccc;
|
||||
box-shadow: 0 1px 6px #ccc;
|
||||
}
|
||||
|
||||
.uni-navbar--border {
|
||||
border-bottom-width: 1rpx;
|
||||
border-bottom-style: solid;
|
||||
border-bottom-color: #eee;
|
||||
border-bottom-width: 1rpx;
|
||||
border-bottom-style: solid;
|
||||
border-bottom-color: #eee;
|
||||
}
|
||||
|
||||
.uni-ellipsis-1 {
|
||||
overflow: hidden;
|
||||
/* #ifndef APP-NVUE */
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
/* #endif */
|
||||
/* #ifdef APP-NVUE */
|
||||
lines: 1;
|
||||
text-overflow: ellipsis;
|
||||
/* #endif */
|
||||
overflow: hidden;
|
||||
/* #ifndef APP-NVUE */
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
/* #endif */
|
||||
/* #ifdef APP-NVUE */
|
||||
lines: 1;
|
||||
text-overflow: ellipsis;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
// 暗主题配置
|
||||
|
|
Loading…
Reference in New Issue