This commit is contained in:
全栈小学生 2023-06-01 19:37:35 +08:00
parent 2370e1a476
commit 602b8f3940
12 changed files with 237 additions and 74 deletions

View File

@ -1,4 +1,4 @@
NODE_ENV = 'development' NODE_ENV = 'production'
# api请求地址 # api请求地址
VITE_APP_BASE_URL='' VITE_APP_BASE_URL=''
@ -7,7 +7,7 @@ VITE_APP_BASE_URL=''
VITE_IMG_DOMAIN='' VITE_IMG_DOMAIN=''
# 站点id 仅在编译为小程序时生效 # 站点id 仅在编译为小程序时生效
VITE_SITE_ID = 1 VITE_SITE_ID = ''
# 本地存储时token的参数名 # 本地存储时token的参数名
VITE_REQUEST_STORAGE_TOKEN_KEY='wapToken' VITE_REQUEST_STORAGE_TOKEN_KEY='wapToken'

View File

@ -2,7 +2,7 @@
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app' import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import manifest from '@/manifest.json' import manifest from '@/manifest.json'
import { redirectInterceptor, launchInterceptor } from '@/utils/interceptor' import { redirectInterceptor, launchInterceptor } from '@/utils/interceptor'
import { getToken, isWeixinBrowser, urlDeconstruction } from '@/utils/common' import { getToken, isWeixinBrowser,getSiteId } from '@/utils/common'
import useMemberStore from '@/stores/member' import useMemberStore from '@/stores/member'
import useConfigStore from '@/stores/config' import useConfigStore from '@/stores/config'
import useSystemStore from '@/stores/system' import useSystemStore from '@/stores/system'
@ -22,6 +22,9 @@
// #ifdef H5 // #ifdef H5
uni.getSystemInfoSync().platform == 'ios' && (uni.setStorageSync('initUrl', location.href)) uni.getSystemInfoSync().platform == 'ios' && (uni.setStorageSync('initUrl', location.href))
// #endif // #endif
// id
if (getSiteId(uni.getStorageSync('wap_site_id') || import.meta.env.VITE_SITE_ID) === '') return;
const configStore = useConfigStore() const configStore = useConfigStore()
configStore.getTabbarConfig() configStore.getTabbarConfig()

View File

@ -1,49 +1,49 @@
{ {
"requestFail": "请求失败", "requestFail": "请求失败",
"notInDomainList": "不在request 合法域名列表中", "notInDomainList": "不在request 合法域名列表中",
"currency": "¥", "currency": "¥",
"getSmsCode": "获取验证码", "getSmsCode": "获取验证码",
"smsCodeChangeText": "秒后重新获取", "smsCodeChangeText": "秒后重新获取",
"captchaTitle": "请完成验证", "captchaTitle": "请完成验证",
"confirm": "确认", "confirm": "确认",
"cancel": "取消", "cancel": "取消",
"save": "保存", "save": "保存",
"delete": "删除", "delete": "删除",
"captchaPlaceholder": "请输入验证码", "captchaPlaceholder": "请输入验证码",
"mobilePlaceholder": "请输入手机号码", "mobilePlaceholder": "请输入手机号码",
"mobileError": "请输入正确的手机号", "mobileError": "请输入正确的手机号",
"codePlaceholder": "请输入手机验证码", "codePlaceholder": "请输入手机验证码",
"memberCenter": "个人中心", "memberCenter": "个人中心",
"userAgreement": "用户协议", "userAgreement": "用户协议",
"privacyAgreement": "隐私协议", "privacyAgreement": "隐私协议",
"nickname": "昵称", "nickname": "昵称",
"nicknamePlaceholder": "请输入昵称", "nicknamePlaceholder": "请输入昵称",
"headimg": "头像", "headimg": "头像",
"headimgPlaceholder": "请设置头像", "headimgPlaceholder": "请设置头像",
"getAvatarNickname": "获取您的昵称头像", "getAvatarNickname": "获取您的昵称头像",
"getAvatarNicknameTips": "获取用户头像、昵称完善个人资料,主要用于向用户提供具有辨识度的用户中心界面", "getAvatarNicknameTips": "获取用户头像、昵称完善个人资料,主要用于向用户提供具有辨识度的用户中心界面",
"point": "积分", "point": "积分",
"balance": "余额", "balance": "余额",
"login": "登录", "login": "登录",
"register": "注册", "register": "注册",
"complete": "完成", "complete": "完成",
"close": "关闭", "close": "关闭",
"pay": { "pay": {
"orderInfo": "订单信息", "orderInfo": "订单信息",
"confirmPay": "确认支付", "confirmPay": "确认支付",
"payTitle": "确认付款", "payTitle": "确认付款",
"notHavePayType": "没有可用的支付方式", "notHavePayType": "没有可用的支付方式",
"notObtainedInfo": "未获取到支付信息", "notObtainedInfo": "未获取到支付信息",
"paymentDocuments": "该支付单据", "paymentDocuments": "该支付单据",
"paySuccess": "支付成功", "paySuccess": "支付成功",
"payFail": "支付失败", "payFail": "支付失败",
"completePay": "已完成支付", "completePay": "已完成支付",
"incompletePay": "未完成支付", "incompletePay": "未完成支付",
"getting": "获取支付结果中" "getting": "获取支付结果中"
}, },
"myBalance": "我的余额", "myBalance": "我的余额",
"myPoint": "我的积分", "myPoint": "我的积分",
"customerService": "联系客服", "customerService": "联系客服",
"siteClose": "站点已关闭", "siteClose": "站点已关闭",
"siteNonexistence": "站点不存在" "siteNonexistence": "站点不存在"
} }

View File

@ -0,0 +1,10 @@
{
"developTitle":"开发环境配置",
"baseUrl":"API请求地址",
"imgUrl":"图片服务器地址",
"siteId":"站点ID",
"siteIdPlaceholder": "请输入站点ID",
"pleaseEnterNumber":"请输入数字",
"maximumCannotExceed":"最大不能超过"
}

View File

@ -6,12 +6,14 @@ import locale from './locale'
import uviewPlus from 'uview-plus' import uviewPlus from 'uview-plus'
import '@/styles/index.scss' import '@/styles/index.scss'
import 'virtual:windi.css' import 'virtual:windi.css'
import { uniStorage } from './utils/storage'
export function createApp() { export function createApp() {
const app = createSSRApp(App) const app = createSSRApp(App)
app.use(Pinia.createPinia()) app.use(Pinia.createPinia())
app.use(locale) app.use(locale)
app.use(uviewPlus) app.use(uviewPlus)
uniStorage()
return { return {
app, app,
Pinia Pinia

View File

@ -259,7 +259,16 @@
// #endif // #endif
"navigationBarTitleText": "%pages.webview.index%" "navigationBarTitleText": "%pages.webview.index%"
} }
}// {{PAGE}} },
{
"path": "pages/index/develop",
"style": {
// #ifdef H5
"navigationStyle": "custom",
// #endif
"navigationBarTitleText": "%pages.index.develop%"
}
}// {{PAGE}}
], ],
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",

View File

@ -0,0 +1,62 @@
<template>
<view class="mt-[80rpx] px-[60rpx]">
<view class="font-bold text-xl mb-[80rpx]">{{t('developTitle')}}</view>
<view class="mb-[40rpx] flex flex-col">
<text class="mb-[10rpx]">{{ t('baseUrl') }}</text>
<text class="text-sm">{{formData.baseUrl}}</text>
</view>
<view class="mb-[40rpx] flex flex-col">
<text class="mb-[10rpx]">{{ t('imgUrl') }}</text>
<text class="text-sm">{{formData.imgUrl}}</text>
</view>
<view class="mb-[40rpx] flex flex-col">
<text class="mb-[20rpx]">{{ t('siteId') }}</text>
<u-input v-model="formData.siteId" clearable :placeholder="t('siteIdPlaceholder')" />
</view>
<u-button type="primary" @click="save" class="mt-[80rpx]">
{{ t('confirm') }}
</u-button>
</view>
</template>
<script setup lang="ts">
import { ref, reactive, computed } from 'vue'
import { img, redirect, getSiteId } from '@/utils/common'
import { t } from '@/locale'
import manifestJson from '@/manifest.json'
const formData = reactive({
siteId: '',
baseUrl: import.meta.env.VITE_APP_BASE_URL || `${location.origin}/api/`,
imgUrl: import.meta.env.VITE_IMG_DOMAIN
})
const save = () => {
if (formData.siteId.length == 0) {
uni.showToast({ title: t('siteIdPlaceholder'), icon: 'none' });
return;
}
var reg = /^[0-9]+$/;
if (!reg.test(formData.siteId)) {
uni.showToast({ title: t('pleaseEnterNumber'), icon: 'none' });
return;
}
if (formData.siteId > 9999999) {
uni.showToast({ title: t('maximumCannotExceed') + '9999999', icon: 'none' });
return;
}
uni.setStorageSync('wap_site_id', formData.siteId);
let url = uni.getStorageSync('develop_before_path') || '/pages/index/index';
if (url == '/pages/index/develop') url = '/pages/index/index';
url = url.replace('/','')
uni.removeStorageSync('develop_before_path');
//
location.href = `${location.origin}${manifestJson.h5.router.base}${url}`
}
</script>
<style lang="scss" scoped></style>

View File

@ -3,7 +3,7 @@ import { getSiteInfo } from '@/api/system'
import { redirect } from '@/utils/common' import { redirect } from '@/utils/common'
interface System { interface System {
site: AnyObject | null site : AnyObject | null
} }
const useSystemStore = defineStore('system', { const useSystemStore = defineStore('system', {
@ -14,15 +14,15 @@ const useSystemStore = defineStore('system', {
}, },
actions: { actions: {
async getSitenfo() { async getSitenfo() {
await getSiteInfo() await getSiteInfo()
.then((res: any) => { .then((res : any) => {
this.site = res.data this.site = res.data
if (this.site.status == 3) redirect({ url: '/pages/index/close', mode: 'reLaunch' }) if (this.site.status == 3) redirect({ url: '/pages/index/close', mode: 'reLaunch' })
}) })
.catch((err) => { .catch((err) => {
redirect({ url: '/pages/index/nonexistence', mode: 'reLaunch' }) redirect({ url: '/pages/index/nonexistence', mode: 'reLaunch' })
}) })
} }
} }
}) })

View File

@ -1,6 +1,7 @@
import { getTabbarPages } from './pages' import { getTabbarPages } from './pages'
import useDiyStore from '@/stores/diy' import useDiyStore from '@/stores/diy'
import useMemberStore from '@/stores/member' import useMemberStore from '@/stores/member'
import internal from 'stream'
/** /**
* *
@ -214,4 +215,19 @@ export function moneyFormat(money : string) : string {
*/ */
export function mobileConceal(mobile : string) : string { export function mobileConceal(mobile : string) : string {
return mobile.substring(0, 3) + "****" + mobile.substr(mobile.length - 4); return mobile.substring(0, 3) + "****" + mobile.substr(mobile.length - 4);
}
/**
* id
*/
export function getSiteId(siteid : number) {
// #ifdef H5
const match = location.href.match(/\/s(\d*)\//);
if (match) return match[1]
else return siteid
// #endif
// #ifndef H5
return siteid
// #endif
} }

View File

@ -1,6 +1,6 @@
import { language } from '@/locale' import { language } from '@/locale'
import { checkNeedLogin } from '@/utils/auth' import { checkNeedLogin } from '@/utils/auth'
import { urlDeconstruction, getToken } from '@/utils/common' import { redirect, urlDeconstruction, getToken, getSiteId } from '@/utils/common'
import { memberLog } from '@/api/auth' import { memberLog } from '@/api/auth'
/** /**
@ -17,6 +17,15 @@ export const redirectInterceptor = () => {
// 加载语言包 // 加载语言包
language.loadLocaleMessages(route.path, uni.getLocale()) language.loadLocaleMessages(route.path, uni.getLocale())
// 开发模式下如果未配置站点ID则跳转到开发环境配置页面
// #ifdef H5
if (process.env.NODE_ENV == 'development') {
if ((getSiteId(uni.getStorageSync('wap_site_id') || import.meta.env.VITE_SITE_ID) === '') && route.path != '/pages/index/develop') {
redirect({ url: '/pages/index/develop', mode: 'reLaunch' })
}
}
// #endif
// 校验是否需要登录 // 校验是否需要登录
checkNeedLogin(route) checkNeedLogin(route)
@ -31,9 +40,25 @@ export const redirectInterceptor = () => {
* *
*/ */
export const launchInterceptor = () => { export const launchInterceptor = () => {
// 加载语言包
const launch = uni.getLaunchOptionsSync() const launch = uni.getLaunchOptionsSync()
launch.path = `/${launch.path}` launch.path = `/${launch.path}`
// 开发模式下如果未配置站点ID则跳转到开发环境配置页面
// #ifdef H5
if (process.env.NODE_ENV == 'development') {
// 后台DIY装修页面时获取站点ID
if (location.search.indexOf('?mode=decorate&site_id=') != -1) {
uni.setStorageSync('wap_site_id', location.search.replace('?mode=decorate&site_id=',''));
}
if (getSiteId(uni.getStorageSync('wap_site_id') || import.meta.env.VITE_SITE_ID) === '') {
launch.path = '/pages/index/develop';
uni.setStorageSync('develop_before_path', launch.path);
redirect({ url: '/pages/index/develop', mode: 'reLaunch' })
}
}
// #endif
// 加载语言包
language.loadLocaleMessages(launch.path, uni.getLocale()) language.loadLocaleMessages(launch.path, uni.getLocale())
// 校验是否需要登录 // 校验是否需要登录
@ -44,12 +69,6 @@ export const launchInterceptor = () => {
uni.setStorageSync('pid', launch.query.mid) uni.setStorageSync('pid', launch.query.mid)
} }
// #ifdef H5
const match = location.href.match(/\/s(\d*)\//);
if (match) uni.setStorageSync('wap_site_id', match[1])
else uni.removeStorageSync('wap_site_id')
// #endif
// 添加会员访问日志 // 添加会员访问日志
if (getToken()) memberLog({ route: launch.path, params: JSON.stringify(launch.query || {}), pre_route: '' }) if (getToken()) memberLog({ route: launch.path, params: JSON.stringify(launch.query || {}), pre_route: '' })
} }

View File

@ -1,6 +1,6 @@
import { getToken, getAppChannel } from './common'
import useMemberStore from '@/stores/member' import useMemberStore from '@/stores/member'
import { t } from '@/locale' import { t } from '@/locale'
import { getToken, getAppChannel, getSiteId } from './common'
interface RequestConfig { interface RequestConfig {
showErrorMessage ?: boolean showErrorMessage ?: boolean
@ -23,13 +23,12 @@ class Request {
// #ifndef H5 // #ifndef H5
this.baseUrl = import.meta.env.VITE_APP_BASE_URL this.baseUrl = import.meta.env.VITE_APP_BASE_URL
// #endif // #endif
// #ifdef MP if (process.env.NODE_ENV == 'development') {
this.config.header[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = import.meta.env.VITE_SITE_ID this.config.header[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = getSiteId(uni.getStorageSync('wap_site_id') || import.meta.env.VITE_SITE_ID)
// #endif } else {
// #ifdef H5 this.config.header[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = getSiteId(import.meta.env.VITE_SITE_ID)
this.config.header[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = uni.getStorageSync('wap_site_id') || import.meta.env.VITE_SITE_ID }
// #endif
this.config.header[import.meta.env.VITE_REQUEST_HEADER_CHANNEL_KEY] = getAppChannel() this.config.header[import.meta.env.VITE_REQUEST_HEADER_CHANNEL_KEY] = getAppChannel()
} }

43
uni-app/utils/storage.ts Normal file
View File

@ -0,0 +1,43 @@
import { getSiteId } from './common'
const handleKey = (key: string) : string => {
const siteid = getSiteId(0)
const storageKey = (siteid ? `site${siteid}.` : '') + key
return storageKey
}
export function uniStorage(){
const setStorageSync = uni.setStorageSync
const setStorage = uni.setStorage
const getStorage = uni.getStorage
const getStorageSync = uni.getStorageSync
const removeStorage = uni.removeStorage
const removeStorageSync = uni.removeStorageSync
uni.setStorage = (options: UniNamespace.SetStorageOptions)=> {
options.key = handleKey(options.key)
setStorage(options)
}
uni.setStorageSync = (key: string, data: any) => {
setStorageSync(handleKey(key), data)
}
uni.getStorage = (options: UniNamespace.GetStorageOptions) => {
options.key = handleKey(options.key)
getStorage(options)
}
uni.getStorageSync = (key: string) => {
return getStorageSync(handleKey(key))
}
uni.removeStorage = (options: UniNamespace.RemoveStorageOptions) => {
options.key = handleKey(options.key)
removeStorage(options)
}
uni.removeStorageSync = (key: string) => {
return removeStorageSync(handleKey(key))
}
}