mirror of
https://gitee.com/niucloud-team/niucloud.git
synced 2026-01-02 18:28:10 +00:00
uni-app
This commit is contained in:
parent
2370e1a476
commit
602b8f3940
@ -1,4 +1,4 @@
|
||||
NODE_ENV = 'development'
|
||||
NODE_ENV = 'production'
|
||||
|
||||
# api请求地址
|
||||
VITE_APP_BASE_URL=''
|
||||
@ -7,7 +7,7 @@ VITE_APP_BASE_URL=''
|
||||
VITE_IMG_DOMAIN=''
|
||||
|
||||
# 站点id 仅在编译为小程序时生效
|
||||
VITE_SITE_ID = 1
|
||||
VITE_SITE_ID = ''
|
||||
|
||||
# 本地存储时token的参数名
|
||||
VITE_REQUEST_STORAGE_TOKEN_KEY='wapToken'
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
|
||||
import manifest from '@/manifest.json'
|
||||
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 useConfigStore from '@/stores/config'
|
||||
import useSystemStore from '@/stores/system'
|
||||
@ -22,6 +22,9 @@
|
||||
// #ifdef H5
|
||||
uni.getSystemInfoSync().platform == 'ios' && (uni.setStorageSync('initUrl', location.href))
|
||||
// #endif
|
||||
|
||||
// 缺少站点id,拦截
|
||||
if (getSiteId(uni.getStorageSync('wap_site_id') || import.meta.env.VITE_SITE_ID) === '') return;
|
||||
|
||||
const configStore = useConfigStore()
|
||||
configStore.getTabbarConfig()
|
||||
|
||||
@ -1,49 +1,49 @@
|
||||
{
|
||||
"requestFail": "请求失败",
|
||||
"notInDomainList": "不在request 合法域名列表中",
|
||||
"currency": "¥",
|
||||
"getSmsCode": "获取验证码",
|
||||
"smsCodeChangeText": "秒后重新获取",
|
||||
"captchaTitle": "请完成验证",
|
||||
"confirm": "确认",
|
||||
"cancel": "取消",
|
||||
"save": "保存",
|
||||
"delete": "删除",
|
||||
"captchaPlaceholder": "请输入验证码",
|
||||
"mobilePlaceholder": "请输入手机号码",
|
||||
"mobileError": "请输入正确的手机号",
|
||||
"codePlaceholder": "请输入手机验证码",
|
||||
"memberCenter": "个人中心",
|
||||
"userAgreement": "用户协议",
|
||||
"privacyAgreement": "隐私协议",
|
||||
"nickname": "昵称",
|
||||
"nicknamePlaceholder": "请输入昵称",
|
||||
"headimg": "头像",
|
||||
"headimgPlaceholder": "请设置头像",
|
||||
"getAvatarNickname": "获取您的昵称头像",
|
||||
"getAvatarNicknameTips": "获取用户头像、昵称完善个人资料,主要用于向用户提供具有辨识度的用户中心界面",
|
||||
"point": "积分",
|
||||
"balance": "余额",
|
||||
"login": "登录",
|
||||
"register": "注册",
|
||||
"complete": "完成",
|
||||
"close": "关闭",
|
||||
"pay": {
|
||||
"orderInfo": "订单信息",
|
||||
"confirmPay": "确认支付",
|
||||
"payTitle": "确认付款",
|
||||
"notHavePayType": "没有可用的支付方式",
|
||||
"notObtainedInfo": "未获取到支付信息",
|
||||
"paymentDocuments": "该支付单据",
|
||||
"paySuccess": "支付成功",
|
||||
"payFail": "支付失败",
|
||||
"completePay": "已完成支付",
|
||||
"incompletePay": "未完成支付",
|
||||
"getting": "获取支付结果中"
|
||||
},
|
||||
"requestFail": "请求失败",
|
||||
"notInDomainList": "不在request 合法域名列表中",
|
||||
"currency": "¥",
|
||||
"getSmsCode": "获取验证码",
|
||||
"smsCodeChangeText": "秒后重新获取",
|
||||
"captchaTitle": "请完成验证",
|
||||
"confirm": "确认",
|
||||
"cancel": "取消",
|
||||
"save": "保存",
|
||||
"delete": "删除",
|
||||
"captchaPlaceholder": "请输入验证码",
|
||||
"mobilePlaceholder": "请输入手机号码",
|
||||
"mobileError": "请输入正确的手机号",
|
||||
"codePlaceholder": "请输入手机验证码",
|
||||
"memberCenter": "个人中心",
|
||||
"userAgreement": "用户协议",
|
||||
"privacyAgreement": "隐私协议",
|
||||
"nickname": "昵称",
|
||||
"nicknamePlaceholder": "请输入昵称",
|
||||
"headimg": "头像",
|
||||
"headimgPlaceholder": "请设置头像",
|
||||
"getAvatarNickname": "获取您的昵称头像",
|
||||
"getAvatarNicknameTips": "获取用户头像、昵称完善个人资料,主要用于向用户提供具有辨识度的用户中心界面",
|
||||
"point": "积分",
|
||||
"balance": "余额",
|
||||
"login": "登录",
|
||||
"register": "注册",
|
||||
"complete": "完成",
|
||||
"close": "关闭",
|
||||
"pay": {
|
||||
"orderInfo": "订单信息",
|
||||
"confirmPay": "确认支付",
|
||||
"payTitle": "确认付款",
|
||||
"notHavePayType": "没有可用的支付方式",
|
||||
"notObtainedInfo": "未获取到支付信息",
|
||||
"paymentDocuments": "该支付单据",
|
||||
"paySuccess": "支付成功",
|
||||
"payFail": "支付失败",
|
||||
"completePay": "已完成支付",
|
||||
"incompletePay": "未完成支付",
|
||||
"getting": "获取支付结果中"
|
||||
},
|
||||
"myBalance": "我的余额",
|
||||
"myPoint": "我的积分",
|
||||
"customerService": "联系客服",
|
||||
"siteClose": "站点已关闭",
|
||||
"siteNonexistence": "站点不存在"
|
||||
"siteClose": "站点已关闭",
|
||||
"siteNonexistence": "站点不存在"
|
||||
}
|
||||
10
uni-app/locale/zh-Hans/pages.index.develop.json
Normal file
10
uni-app/locale/zh-Hans/pages.index.develop.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"developTitle":"开发环境配置",
|
||||
"baseUrl":"API请求地址",
|
||||
"imgUrl":"图片服务器地址",
|
||||
"siteId":"站点ID",
|
||||
"siteIdPlaceholder": "请输入站点ID",
|
||||
"pleaseEnterNumber":"请输入数字",
|
||||
"maximumCannotExceed":"最大不能超过"
|
||||
|
||||
}
|
||||
@ -6,12 +6,14 @@ import locale from './locale'
|
||||
import uviewPlus from 'uview-plus'
|
||||
import '@/styles/index.scss'
|
||||
import 'virtual:windi.css'
|
||||
import { uniStorage } from './utils/storage'
|
||||
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
app.use(Pinia.createPinia())
|
||||
app.use(locale)
|
||||
app.use(uviewPlus)
|
||||
uniStorage()
|
||||
return {
|
||||
app,
|
||||
Pinia
|
||||
|
||||
@ -259,7 +259,16 @@
|
||||
// #endif
|
||||
"navigationBarTitleText": "%pages.webview.index%"
|
||||
}
|
||||
}// {{PAGE}}
|
||||
},
|
||||
{
|
||||
"path": "pages/index/develop",
|
||||
"style": {
|
||||
// #ifdef H5
|
||||
"navigationStyle": "custom",
|
||||
// #endif
|
||||
"navigationBarTitleText": "%pages.index.develop%"
|
||||
}
|
||||
}// {{PAGE}}
|
||||
],
|
||||
"globalStyle": {
|
||||
"navigationBarTextStyle": "black",
|
||||
|
||||
62
uni-app/pages/index/develop.vue
Normal file
62
uni-app/pages/index/develop.vue
Normal 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>
|
||||
@ -3,7 +3,7 @@ import { getSiteInfo } from '@/api/system'
|
||||
import { redirect } from '@/utils/common'
|
||||
|
||||
interface System {
|
||||
site: AnyObject | null
|
||||
site : AnyObject | null
|
||||
}
|
||||
|
||||
const useSystemStore = defineStore('system', {
|
||||
@ -14,15 +14,15 @@ const useSystemStore = defineStore('system', {
|
||||
},
|
||||
actions: {
|
||||
async getSitenfo() {
|
||||
await getSiteInfo()
|
||||
.then((res: any) => {
|
||||
this.site = res.data
|
||||
if (this.site.status == 3) redirect({ url: '/pages/index/close', mode: 'reLaunch' })
|
||||
})
|
||||
.catch((err) => {
|
||||
redirect({ url: '/pages/index/nonexistence', mode: 'reLaunch' })
|
||||
})
|
||||
}
|
||||
await getSiteInfo()
|
||||
.then((res : any) => {
|
||||
this.site = res.data
|
||||
if (this.site.status == 3) redirect({ url: '/pages/index/close', mode: 'reLaunch' })
|
||||
})
|
||||
.catch((err) => {
|
||||
redirect({ url: '/pages/index/nonexistence', mode: 'reLaunch' })
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { getTabbarPages } from './pages'
|
||||
import useDiyStore from '@/stores/diy'
|
||||
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 {
|
||||
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
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
import { language } from '@/locale'
|
||||
import { checkNeedLogin } from '@/utils/auth'
|
||||
import { urlDeconstruction, getToken } from '@/utils/common'
|
||||
import { redirect, urlDeconstruction, getToken, getSiteId } from '@/utils/common'
|
||||
import { memberLog } from '@/api/auth'
|
||||
|
||||
/**
|
||||
@ -17,6 +17,15 @@ export const redirectInterceptor = () => {
|
||||
// 加载语言包
|
||||
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)
|
||||
|
||||
@ -31,9 +40,25 @@ export const redirectInterceptor = () => {
|
||||
* 应用初始化拦截器
|
||||
*/
|
||||
export const launchInterceptor = () => {
|
||||
// 加载语言包
|
||||
const launch = uni.getLaunchOptionsSync()
|
||||
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())
|
||||
|
||||
// 校验是否需要登录
|
||||
@ -44,12 +69,6 @@ export const launchInterceptor = () => {
|
||||
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: '' })
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
import { getToken, getAppChannel } from './common'
|
||||
import useMemberStore from '@/stores/member'
|
||||
import { t } from '@/locale'
|
||||
import { getToken, getAppChannel, getSiteId } from './common'
|
||||
|
||||
interface RequestConfig {
|
||||
showErrorMessage ?: boolean
|
||||
@ -23,13 +23,12 @@ class Request {
|
||||
// #ifndef H5
|
||||
this.baseUrl = import.meta.env.VITE_APP_BASE_URL
|
||||
// #endif
|
||||
|
||||
// #ifdef MP
|
||||
this.config.header[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = import.meta.env.VITE_SITE_ID
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
this.config.header[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = uni.getStorageSync('wap_site_id') || import.meta.env.VITE_SITE_ID
|
||||
// #endif
|
||||
|
||||
if (process.env.NODE_ENV == 'development') {
|
||||
this.config.header[import.meta.env.VITE_REQUEST_HEADER_SITEID_KEY] = getSiteId(uni.getStorageSync('wap_site_id') || import.meta.env.VITE_SITE_ID)
|
||||
} else {
|
||||
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_CHANNEL_KEY] = getAppChannel()
|
||||
}
|
||||
|
||||
43
uni-app/utils/storage.ts
Normal file
43
uni-app/utils/storage.ts
Normal 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))
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user