diff --git a/README.md b/README.md index 06ed1df4970f92fa282bb8801224dc7cfe20144e..84623e6337dee0e07b428e0c6c08a617427a378a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ `base app`,是一个云端一体的、集成了商用项目开发常见功能的项目模板。 如果说uniCloud admin是管理端项目的基础模板,那么base app则是用户端、尤其是移动端的基础模板。 在HBuilderX新建项目时选择base app项目模板,在这个模板基础之上快速填充自己的业务,即可很快完成一个应用。 -地址:[https://gitee.com/dcloud/base-app](https://gitee.com/dcloud/base-app) +地址:[https://gitee.com/dcloud/uni-starter](https://gitee.com/dcloud/uni-starter) #### 项目背景 我们一直想出一个结合uni-app、uniCloud和openDB以及uni-id和uniCloud admin等,uni全家桶的项目模板; @@ -48,7 +48,7 @@ base app将节省开发者大量的时间,让开发者集中精力在自己的 有了base app,再加上schema2code生成前端页面,一个简单应用就可以快速完成。 base app + uniCloud admin,应用开发从未如此简单快捷! -base app提供了baseapp.config.js,可指定该应用是否强制登录才能进入首页,可配置选择登录注册方式以及不同方式的优先级等。 +base app提供了uni-starter.config.js,可指定该应用是否强制登录才能进入首页,可配置选择登录注册方式以及不同方式的优先级等。 ``` module.exports = { @@ -59,7 +59,7 @@ module.exports = { //点击悬浮下载栏后打开的网页链接 "openUrl": 'https://sj.qq.com/myapp/detail.htm?apkName=com.tencent.android.qqdownloader&info=6646FD239A6EBA9E2DEE5DFC7E18D867', //左侧显示的应用名称 - "appname": 'base-app', + "appname": 'uni-starter', //应用的图标 "logo": './static/logo.png', } @@ -87,7 +87,7 @@ module.exports = { //关于应用 "about": { //应用名称 - "appName": "base-app", + "appName": "uni-starter", //应用logo "logo": "/static/logo.png", //公司名称 @@ -119,11 +119,11 @@ module.exports = { ### 应用配置 #### 目录结构
-base-app
+uni-starter
 ├─uniCloud-aliyun	
 │	├─cloudfunctions 云函数目录
 │	|	├─common 公共模块
-│	│	|	├─uni-config-center		baseapp的服务端配置中心,项目所有云函数的配置在这里填写
+│	│	|	├─uni-config-center		uni-starter的服务端配置中心,项目所有云函数的配置在这里填写
 │	│	|	|	├─index.js			config-center入口文件
 │	│	|	|	└─uni-id			uni-id模块配置目录
 │	│	|	|		├─config.json	uni-id对应的配置数据
@@ -199,7 +199,7 @@ base-app
 ├─uni_modules						存放[uni_module](/uni_modules)规范的插件。
 ├─main.js							Vue初始化入口文件
 ├─App.vue							应用配置,用来配置App全局样式以及监听 应用生命周期
-├─baseconfig						baseapp的前端的配置文件,项目所有模块的配置在这里填写。详见该文件的代码注释。
+├─baseconfig						uni-starter的前端的配置文件,项目所有模块的配置在这里填写。详见该文件的代码注释。
 ├─manifest.json	 					配置应用名称、appid、logo、版本等打包信息,详见
 └─pages.json						配置页面路由、导航条、选项卡等页面类信息,详见
 
@@ -229,7 +229,7 @@ base-app } ``` 1. onLaunch还执行了initApp()包含以下操作 - 1. 读取baseapp.config并挂载到globalData的config下 + 1. 读取uni-starter.config并挂载到globalData的config下 2. 读取应用版本号,并存到globalData下。 3. 检查是否有可更新的应用版本。 4. 网络的变化与toast方式提醒 diff --git a/baseapp.config.js b/baseapp.config.js index 86fddfddfd2ca1e67a32f310181236cecf9f2fde..6c049ca46e25b3e5d5fbbd0aeed00730a62a9b00 100644 --- a/baseapp.config.js +++ b/baseapp.config.js @@ -7,7 +7,7 @@ module.exports = { //点击悬浮下载栏后打开的网页链接 "openUrl": 'https://sj.qq.com/myapp/detail.htm?apkName=com.tencent.android.qqdownloader&info=6646FD239A6EBA9E2DEE5DFC7E18D867', //左侧显示的应用名称 - "appname": 'base-app', + "appname": 'uni-starter', //应用的图标 "logo": './static/logo.png', } @@ -35,7 +35,7 @@ module.exports = { //关于应用 "about": { //应用名称 - "appName": "base-app", + "appName": "uni-starter", //应用logo "logo": "/static/logo.png", //公司名称 diff --git a/common/appInit.js b/common/appInit.js index bd57620c0f1681fbcdcd055b983929772aef7348..6fc6c967865c62b112531e05d9a60dd929d00ffd 100644 --- a/common/appInit.js +++ b/common/appInit.js @@ -1,18 +1,18 @@ -import baseappConfig from '@/baseapp.config.js'; +import uniStarterConfig from '@/uni-starter.config.js'; //应用初始化页 -// #ifdef APP-PLUS -import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'; -import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version'; -// #endif +// #ifdef APP-PLUS +import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'; +import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version'; +// #endif export default function() { setTimeout(()=>{ - // baseappConfig挂载到getApp(). + // uniStarterConfig挂载到getApp(). const app = getApp({allowDefault: true}) - app.globalData.config = baseappConfig; + app.globalData.config = uniStarterConfig; },30) - - // 初始化appVersion(仅app生效) + + // 初始化appVersion(仅app生效) initAppVersion(); /* 这里应用了[拦截器](https://uniapp.dcloud.io/api/interceptor?id=addinterceptor)实现了,路由拦截。当应用无访问摄像头/相册权限,引导跳到设置界面 @@ -23,84 +23,84 @@ export default function() { needLogin, login } - } = baseappConfig //需要登陆的页面 - let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]; - list.forEach(item => { - uni.addInterceptor(item, { - invoke(e) { // 调用前拦截 - //console.log(e); - const token = uni.getStorageSync('uni_id_token') - // console.log(token); - const url = e.url.split('?')[0] - //拦截强制登陆页面 - if (needLogin.includes(url) && token == '') { - console.log('该页面需要登陆,即将跳转到login页面'); - uni.showToast({ - title: '该页面需要登陆,即将跳转到login页面', - icon: 'none' - }) - uni.navigateTo({ - url: "/pages/ucenter/login-page/index/index" - }) - return false - } - //控制登陆优先级 - if (url == '/pages/ucenter/login-page/index/index') { - //一键登录(uniVerify)、账号(username)、验证码登陆(短信smsCode) - if (login[0] == 'uniVerify') { - // console.log(e.url,url); - if (e.url == url) { - e.url += '?' - } - e.url += "univerify_first=true" - } else if (login[0] == 'username') { - e.url = "/pages/ucenter/login-page/pwd-login/pwd-login" - } - } - return true - }, - fail(err) { // 失败回调拦截 - console.log(err); - }, - }) - }) + } = uniStarterConfig //需要登陆的页面 + let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]; + list.forEach(item => { + uni.addInterceptor(item, { + invoke(e) { // 调用前拦截 + //console.log(e); + const token = uni.getStorageSync('uni_id_token') + // console.log(token); + const url = e.url.split('?')[0] + //拦截强制登陆页面 + if (needLogin.includes(url) && token == '') { + console.log('该页面需要登陆,即将跳转到login页面'); + uni.showToast({ + title: '该页面需要登陆,即将跳转到login页面', + icon: 'none' + }) + uni.navigateTo({ + url: "/pages/ucenter/login-page/index/index" + }) + return false + } + //控制登陆优先级 + if (url == '/pages/ucenter/login-page/index/index') { + //一键登录(uniVerify)、账号(username)、验证码登陆(短信smsCode) + if (login[0] == 'uniVerify') { + // console.log(e.url,url); + if (e.url == url) { + e.url += '?' + } + e.url += "univerify_first=true" + } else if (login[0] == 'username') { + e.url = "/pages/ucenter/login-page/pwd-login/pwd-login" + } + } + return true + }, + fail(err) { // 失败回调拦截 + console.log(err); + }, + }) + }) + - - //当应用无访问摄像头/相册权限,引导跳到设置界面 - uni.addInterceptor('chooseImage', { - fail(e) { // 失败回调拦截 - console.log(e); - if ( - e.errCode === 11 && uni.getSystemInfoSync().platform == "android" || - e.errCode === 2 && uni.getSystemInfoSync().platform == "ios" - ){ - uni.showModal({ - title:"无法访问摄像头", - content: "当前无摄像头访问权限,建议前往设置", - confirmText: "前往设置", - success(e) { - if (e.confirm) { - openAppPermissionSetting() - } - } - }); - } - if(e.errCode === 12 && uni.getSystemInfoSync().platform == "android"){ - uni.showModal({ - title:"无法访问相册", - content: "当前无系统相册访问权限,建议前往设置", - confirmText: "前往设置", - success(e) { - if (e.confirm) { - openAppPermissionSetting() - } - } - }); - } - } - }) - -// #ifdef APP-PLUS + //当应用无访问摄像头/相册权限,引导跳到设置界面 + uni.addInterceptor('chooseImage', { + fail(e) { // 失败回调拦截 + console.log(e); + if ( + e.errCode === 11 && uni.getSystemInfoSync().platform == "android" || + e.errCode === 2 && uni.getSystemInfoSync().platform == "ios" + ){ + uni.showModal({ + title:"无法访问摄像头", + content: "当前无摄像头访问权限,建议前往设置", + confirmText: "前往设置", + success(e) { + if (e.confirm) { + openAppPermissionSetting() + } + } + }); + } + if(e.errCode === 12 && uni.getSystemInfoSync().platform == "android"){ + uni.showModal({ + title:"无法访问相册", + content: "当前无系统相册访问权限,建议前往设置", + confirmText: "前往设置", + success(e) { + if (e.confirm) { + openAppPermissionSetting() + } + } + }); + } + } + }) + +// #ifdef APP-PLUS // 监听并提示设备网络状态变化 uni.onNetworkStatusChange(res=> { console.log(res.isConnected); @@ -118,38 +118,38 @@ export default function() { duration:3000 }) } - }); -// #endif - -} -/** - * // 初始化appVersion - */ -function initAppVersion() { - // #ifdef APP-PLUS - let appid = plus.runtime.appid; - plus.runtime.getProperty(appid, (wgtInfo) => { - let appVersion = plus.runtime; - let currentVersion = appVersion.versionCode > wgtInfo.versionCode ? appVersion : wgtInfo; - getApp({ - allowDefault: true - }).appVersion = { - ...currentVersion, - appid, - hasNew: false - } - // 检查更新小红点 - callCheckVersion().then(res => { - console.log('检查是否有可以更新的版本', res); - if (res.result.code > 0) { - // 有新版本 - getApp({ - allowDefault: true - }).appVersion.hasNew = true; - } - }) - }); - // 检查更新 - checkUpdate(); - // #endif + }); +// #endif + +} +/** + * // 初始化appVersion + */ +function initAppVersion() { + // #ifdef APP-PLUS + let appid = plus.runtime.appid; + plus.runtime.getProperty(appid, (wgtInfo) => { + let appVersion = plus.runtime; + let currentVersion = appVersion.versionCode > wgtInfo.versionCode ? appVersion : wgtInfo; + getApp({ + allowDefault: true + }).appVersion = { + ...currentVersion, + appid, + hasNew: false + } + // 检查更新小红点 + callCheckVersion().then(res => { + console.log('检查是否有可以更新的版本', res); + if (res.result.code > 0) { + // 有新版本 + getApp({ + allowDefault: true + }).appVersion.hasNew = true; + } + }) + }); + // 检查更新 + checkUpdate(); + // #endif } \ No newline at end of file diff --git a/common/openApp.js b/common/openApp.js index 15c4529c17c5d8d52b069360ce599916895d16ec..5b8e551a53d6274133690c09baf0d59505686ff7 100644 --- a/common/openApp.js +++ b/common/openApp.js @@ -1,36 +1,36 @@ /* 创建在h5端全局悬浮引导用户下载app的功能, - 如不需要本功能直接移除配置文件baseapp.config.js下的h5/openApp即可 + 如不需要本功能直接移除配置文件uni-starter.config.js下的h5/openApp即可 */ -import CONFIG from '../baseapp.config.js'; - +import CONFIG from '../uni-starter.config.js'; + const CONFIG_OPEN = CONFIG?.h5?.openApp?.openUrl ? CONFIG.h5.openApp : {}; -// 仅H5端添加"打开APP" +// 仅H5端添加"打开APP" export default function() { - // #ifdef H5 - if (!CONFIG_OPEN.openUrl) return; - - let openLogo = CONFIG_OPEN.logo ? - `` : ''; - let openApp = document.createElement("div"); + // #ifdef H5 + if (!CONFIG_OPEN.openUrl) return; + + let openLogo = CONFIG_OPEN.logo ? + `` : ''; + let openApp = document.createElement("div"); openApp.id = 'openApp'; - openApp.style = - 'position: fixed;background:#FFFFFF;box-shadow: #eeeeee 1px 1px 9px; ;top: 0;left: 0;right: 0;z-index: 999;width: 100%;height: 45px;display: flex;flex-direction: row;justify-content: space-between;align-items: center;box-sizing: border-box;padding: 0 0.5rem;' - openApp.innerHTML = ` -
- ${openLogo} -
${CONFIG_OPEN.appname || ''}
-
-
下载app
- `; - document.body.insertBefore(openApp, document.body.firstChild); - document.body.style = 'height:calc(100% - 45px); margin-top:45px;'; - openApp.addEventListener('click', e => { - var target = e.target || e.srcElement; - if (target.className.indexOf('openBtn') >= 0) { - window.location.href = CONFIG_OPEN.openUrl; - } + openApp.style = + 'position: fixed;background:#FFFFFF;box-shadow: #eeeeee 1px 1px 9px; ;top: 0;left: 0;right: 0;z-index: 999;width: 100%;height: 45px;display: flex;flex-direction: row;justify-content: space-between;align-items: center;box-sizing: border-box;padding: 0 0.5rem;' + openApp.innerHTML = ` +
+ ${openLogo} +
${CONFIG_OPEN.appname || ''}
+
+
下载app
+ `; + document.body.insertBefore(openApp, document.body.firstChild); + document.body.style = 'height:calc(100% - 45px); margin-top:45px;'; + openApp.addEventListener('click', e => { + var target = e.target || e.srcElement; + if (target.className.indexOf('openBtn') >= 0) { + window.location.href = CONFIG_OPEN.openUrl; + } }) - //#endif + //#endif } diff --git a/components/uni-agreements/uni-agreements.vue b/components/uni-agreements/uni-agreements.vue index eabfc1d1a6f36aefb310d8246043477ce3fbc0f8..2e0ee6af294aece50fc2e8bb67a08b8d04995fac 100644 --- a/components/uni-agreements/uni-agreements.vue +++ b/components/uni-agreements/uni-agreements.vue @@ -1,6 +1,9 @@