提交 2df5b396 编写于 作者: 芊里

大体布局

上级 5c0787c0
<script> <script>
import initApp from '@/common/appInit.js';
export default { export default {
globalData: { globalData: {
searchText: '' searchText: '',
appVersion:{}
}, },
onLaunch: function() { onLaunch: function() {
//#ifdef APP-PLUS //#ifdef APP-PLUS
...@@ -11,6 +13,10 @@ ...@@ -11,6 +13,10 @@
}); });
//#endif //#endif
console.log('App Launch') console.log('App Launch')
initApp();
}, },
onShow: function() { onShow: function() {
console.log('App Show') console.log('App Show')
......
MIT License Apache License
Version 2.0, January 2004
Copyright (c) 2021 崔红保 http://www.apache.org/licenses/
Permission is hereby granted, free of charge, to any person obtaining a copy TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights 1. Definitions.
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is "License" shall mean the terms and conditions for use, reproduction,
furnished to do so, subject to the following conditions: and distribution as defined by Sections 1 through 9 of this document.
The above copyright notice and this permission notice shall be included in all "Licensor" shall mean the copyright owner or entity authorized by
copies or substantial portions of the Software. the copyright owner that is granting the License.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR "Legal Entity" shall mean the union of the acting entity and all
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, other entities that control, are controlled by, or are under common
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE control with that entity. For the purposes of this definition,
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "control" means (i) the power, direct or indirect, to cause the
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, direction or management of such entity, whether by contract or
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE otherwise, or (ii) ownership of fifty percent (50%) or more of the
SOFTWARE. outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
# base-app ## 什么是 uniCloud
base-app是基于uni-app和uniCloud开发的云端一体项目模板,地址:https://gitee.com/dcloud/base-app.git uniCloud 是 DCloud 联合阿里云、腾讯云,为开发者提供的基于 serverless 模式和 js 编程的云开发平台,更多请参考[uniCloud 文档](https://uniapp.dcloud.io/uniCloud)
## 云端一体搜索模板解决了什么问题?
## 使用方式 uniCloud 云端一体搜索模板,自带下拉候选、历史搜索、热搜。无需再开发服务器代码
### 导入/下载项目后,使用HBuilderX 打开即可运行体验。 云端一体搜索模板有以下功能点:
### 用户需要绑定uniCloud服务空间,并运行云服务空间初始化向导。 - 热词设置,可自定义,回车默认搜索热词
- 搜索历史,本地历史,去重排序删除
- 搜索记录,自动向云端储存搜索记录,可用于归纳搜索发现
- 搜索发现,向用户展现热搜
- 搜索联想,基于 uni-list 实现搜索联想列表,兼容 nvue,高性能
- APP 端语音输入,解放双手
- 兼容 nvue
## 特点 前后一体,兼容 nvue,只需导入插件,初始化数据库即可拥有上述功能。
### 兼容多平台 您也可以自己修改逻辑自定义数据库字段,和随意定制 UI 样式。
### app开发基础功能已完成,开发者只需要关心自己的业务部分。 ## 体验步骤
### 使用uniCloud云端一体化项目模板,使用openDB体系构建部分功能,方便开发者后续集成 1. 下载或导入示例项目,绑定一个 uniCloud 服务空间。需 HBuilderX 3.0 以上版本
## 平台支持 2. 在项目的 uniCloud/database 目录下找到 db_init.json,对其点右键执行初始化数据库。这样会给服务空间创建 3 个表:opendb-search-log、opendb-search-hot、opendb-mall-goods。如果之前存在相同表,建议删除后重新执行数据库初始化。
### app 3. 运行示例项目到任意平台,H5、App、小程序均可。
### H5 4. 运行后首页是商品列表,上面有搜索框。点击搜索框进入搜索页面,输入待搜索的商品名称会在下方拉出候选,确认搜索后会返回商品列表页面,列表内容即为搜索结果。
### 微信小程序 5. 在项目的 uniCloud/cloudfunctions 目录下找到云函数 uni-analyse-searchhot,点右键上传到服务空间,该云函数会定时运行,统计和计算近期热搜关键字,并体现在搜索界面的热搜候选词中。
### 百度小程序 ## 项目代码说明
### 支付宝小程序 ### uniCloud 数据表
### 头条小程序 数据表基于 [openDB](https://gitee.com/dcloud/opendb/tree/master) 规范,它约定了一个标准用户表的表名和字段定义,并且基于 nosql 的特性,可以由开发者自行扩展字段。
### QQ小程序 本项目用到了 3 个表:
## 注意事项 - opendb-search-log:搜索日志表。每次搜索,都会将搜索词记录在该表中。[详见](https://gitee.com/dcloud/opendb/tree/master/collection/opendb-search-log)
- opendb-search-hot:热搜表。通过其他云函数定期分析搜索日志表,提取近期热搜词,存入热搜表。[详见](https://gitee.com/dcloud/opendb/tree/master/collection/opendb-search-hot)
- opendb-mall-goods:用于本示例演示的商品列表。实际项目中,可自行提供为需要搜索的表。[详见](https://gitee.com/dcloud/opendb/tree/master/collection/opendb-mall-goods)
### 用户需要自行开通一键登录功能 这些表在 uniCloud Web 控制台中新建表的界面,均可以选择。
*XMind - Trial Version* ### 云函数
\ No newline at end of file
- `uni-analyse-searchhot`
> - 这是一个定时运行的跑批云函数。用于从搜索日志表中归纳热搜。默认归纳最近`7天`搜索记录,截取其中`10`条,可在云函数中进行修改
> - 在`package.json`中有其触发器配置,默认`每2小时`运行一次,可在配置中修改。部署在云端后,也可以在 web 控制台修改。定时触发器使用[cron 表达式](https://uniapp.dcloud.net.cn/uniCloud/trigger)
> - _`注意`_ 该云函数本地运行不生效,需要上传部署至云端
### 前端页面
首页是商品列表页面,点击顶部的搜索框,进入搜索页面。
前端页面基于 [unicloud-db](https://uniapp.dcloud.net.cn/uniCloud/unicloud-db) 组件操作数据库。
商品列表页面是基于 [云端一体商品列表模板](https://ext.dcloud.net.cn/plugin?id=2651) 改进而来。
页面示例搜索的是“opendb-mall-goods”表,可以在页面中的clientDB组件中修改collection属性,指向新的数据表进行搜索。
\ No newline at end of file
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
export default function (){
// 初始化appVersion
initAppVersion();
// 检查更新
checkUpdate();
}
function initAppVersion(){
let appid = plus.runtime.appid;
plus.runtime.getProperty(appid ,(wgtInfo) => {
wgtInfo.version
let appVersion = plus.runtime;
getApp({allowDefault: true}).appVersion = {
appid,
version:appVersion,
wgtVersion:wgtInfo,
finall:appVersion.versionCode > wgtInfo.versionCode ? appVersion : wgtInfo
}
});
}
\ No newline at end of file
/**
* 判断Push是否开启
*/
function isTurnedOnPush(){
var isOn = undefined;
try{
if('iOS' == plus.os.name){
var types = 0;
var app = plus.ios.invoke('UIApplication', 'sharedApplication');
var settings = plus.ios.invoke(app, 'currentUserNotificationSettings');
if(settings){
types = settings.plusGetAttribute('types');
plus.ios.deleteObject(settings);
}else{
types = plus.ios.invoke(app, 'enabledRemoteNotificationTypes');
}
plus.ios.deleteObject(app);
isOn = (0!=types);
}else{
var main = plus.android.runtimeMainActivity();
var manager = plus.android.invoke('com.igexin.sdk.PushManager', 'getInstance');
isOn = plus.android.invoke(manager, 'isPushTurnedOn', main);
}
}catch(e){
console.error('exception in isTurnedOnPush@dc-push!!');
}
return isOn;
}
/**
* 打开Push
* Android平台 - 打开个推(UniPush)的推送通道
* iOS平台 - 如果开启通知功能,则打开应用的设置页面引导用户开启通知
*/
function turnOnPush(){
try{
if('iOS' == plus.os.name){
// 如果设置中没有开启通知,则打开应用的设置界面
if(!isTurnedOnPush()){
settingInIos();
}
}else{
var main = plus.android.runtimeMainActivity();
var manager = plus.android.invoke('com.igexin.sdk.PushManager', 'getInstance');
plus.android.invoke(manager, 'turnOnPush', main);
}
}catch(e){
console.error('exception in turnOnPush@dc-push!!');
}
}
/**
* 关闭Push
* Android平台 - 关闭个推(UniPush)的推送通道
* iOS平台 - 不做任何操作
*/
function trunOffPush(){
try{
if('iOS' == plus.os.name){
// 这里不做任何操作(不引导用户关闭应用的推送能力),应该通知业务服务器不向此用户下发推送消息
}else{
var main = plus.android.runtimeMainActivity();
var manager = plus.android.invoke('com.igexin.sdk.PushManager', 'getInstance');
plus.android.invoke(manager, 'turnOffPush', main);
}
}catch(e){
console.error('exception in trunOffPush@dc-push!!');
}
}
/**
* iOS平台打开应用设置界面
*/
function settingInIos(){
try{
if('iOS' == plus.os.name){
var app = plus.ios.invoke('UIApplication', 'sharedApplication');
var setting = plus.ios.invoke('NSURL', 'URLWithString:', 'app-settings:');
plus.ios.invoke(app, 'openURL:', setting);
plus.ios.deleteObject(setting);
plus.ios.deleteObject(app);
}
}catch(e){
console.error('exception in settingInIos@dc-push!!');
}
}
/**
* android打开应用设置页面
*/
function settingInAndroid(){
if (uni.getSystemInfoSync().platform == "android") {
var main = plus.android.runtimeMainActivity();
var Intent = plus.android.importClass('android.content.Intent');
var Settings = plus.android.importClass('android.provider.Settings');
var intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
// 安卓跳转设置页面详细查看(https://ask.dcloud.net.cn/question/14732)
main.startActivity(intent);
}
}
/**
* 打开应用设置界面
*/
function setting(){
if (uni.getSystemInfoSync().platform == "ios") {
settingInIos();
}
if (uni.getSystemInfoSync().platform == "android") {
settingInAndroid();
}
}
module.exports = {
isOn: isTurnedOnPush,
iosSetting: settingInIos,
on: turnOnPush,
off: trunOffPush,
setting:setting
}
@font-face {
font-family: uniicons;
font-weight: normal;
font-style: normal;
src: url('~@/static/uni.ttf') format('truetype');
}
/*通用 */
view{
font-size:28rpx;
line-height:1.8;
}
progress, checkbox-group{
width: 100%;
}
form {
width: 100%;
}
.uni-flex {
display: flex;
flex-direction: row;
}
.uni-flex-item {
flex: 1;
}
.uni-row {
flex-direction: row;
}
.uni-column {
flex-direction: column;
}
.uni-link{
color:#576B95;
font-size:26rpx;
}
.uni-center{
text-align:center;
}
.uni-inline-item{
display: flex;
flex-direction: row;
align-items:center;
}
.uni-inline-item text{
margin-right: 20rpx;
}
.uni-inline-item text:last-child{
margin-right: 0rpx;
margin-left: 20rpx;
}
/* page */
.uni-page-head{
padding:35rpx;
text-align: center;
}
.uni-page-head-title {
display: inline-block;
padding: 0 40rpx;
font-size: 30rpx;
height: 88rpx;
line-height: 88rpx;
color: #BEBEBE;
box-sizing: border-box;
border-bottom: 2rpx solid #D8D8D8;
}
.uni-page-body {
width: 100%;
flex-grow: 1;
overflow-x: hidden;
}
.uni-padding-wrap{
width:690rpx;
padding:0 30rpx;
}
.uni-word {
text-align: center;
padding:200rpx 100rpx;
}
.uni-title {
font-size:30rpx;
font-weight:500;
padding:20rpx 0;
line-height:1.5;
}
.uni-text{
font-size:28rpx;
}
.uni-title text{
font-size:24rpx;
color:#888;
}
.uni-text-gray{
color: #ccc;
}
.uni-text-small {
font-size:24rpx;
}
.uni-common-mb{
margin-bottom:30rpx;
}
.uni-common-pb{
padding-bottom:30rpx;
}
.uni-common-pl{
padding-left:30rpx;
}
.uni-common-mt{
margin-top:30rpx;
}
/* 背景色 */
.uni-bg-red{
background:#F76260; color:#FFF;
}
.uni-bg-green{
background:#09BB07; color:#FFF;
}
.uni-bg-blue{
background:#007AFF; color:#FFF;
}
/* 标题 */
.uni-h1 {font-size: 80rpx; font-weight:700;}
.uni-h2 {font-size: 60rpx; font-weight:700;}
.uni-h3 {font-size: 48rpx; font-weight:700;}
.uni-h4 {font-size: 36rpx; font-weight:700;}
.uni-h5 {font-size: 28rpx; color: #8f8f94;}
.uni-h6 {font-size: 24rpx; color: #8f8f94;}
.uni-bold{font-weight:bold;}
/* 文本溢出隐藏 */
.uni-ellipsis {overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
/* 竖向百分百按钮 */
.uni-btn-v{
padding:10rpx 0;
}
.uni-btn-v button{margin:20rpx 0;}
/* 表单 */
.uni-form-item{
display:flex;
width:100%;
padding:10rpx 0;
}
.uni-form-item .title{
padding:10rpx 25rpx;
}
.uni-label {
width: 210rpx;
word-wrap: break-word;
word-break: break-all;
text-indent:20rpx;
}
.uni-input {
height: 50rpx;
padding: 15rpx 25rpx;
line-height:50rpx;
font-size:28rpx;
background:#FFF;
flex: 1;
}
radio-group, checkbox-group{
width:100%;
}
radio-group label, checkbox-group label{
padding-right:20rpx;
}
.uni-form-item .with-fun{
display:flex;
flex-wrap:nowrap;
background:#FFFFFF;
}
.uni-form-item .with-fun .uni-icon{
width:40px;
height:80rpx;
line-height:80rpx;
flex-shrink:0;
}
/* loadmore */
.uni-loadmore{
height:80rpx;
line-height:80rpx;
text-align:center;
padding-bottom:30rpx;
}
/*数字角标*/
.uni-badge,
.uni-badge-default {
font-family: 'Helvetica Neue', Helvetica, sans-serif;
font-size: 12px;
line-height: 1;
display: inline-block;
padding: 3px 6px;
color: #333;
border-radius: 100px;
background-color: rgba(0, 0, 0, .15);
}
.uni-badge.uni-badge-inverted {
padding: 0 5px 0 0;
color: #929292;
background-color: transparent
}
.uni-badge-primary {
color: #fff;
background-color: #007aff
}
.uni-badge-blue.uni-badge-inverted,
.uni-badge-primary.uni-badge-inverted {
color: #007aff;
background-color: transparent
}
.uni-badge-green,
.uni-badge-success {
color: #fff;
background-color: #4cd964;
}
.uni-badge-green.uni-badge-inverted,
.uni-badge-success.uni-badge-inverted {
color: #4cd964;
background-color: transparent
}
.uni-badge-warning,
.uni-badge-yellow {
color: #fff;
background-color: #f0ad4e
}
.uni-badge-warning.uni-badge-inverted,
.uni-badge-yellow.uni-badge-inverted {
color: #f0ad4e;
background-color: transparent
}
.uni-badge-danger,
.uni-badge-red {
color: #fff;
background-color: #dd524d
}
.uni-badge-danger.uni-badge-inverted,
.uni-badge-red.uni-badge-inverted {
color: #dd524d;
background-color: transparent
}
.uni-badge-purple,
.uni-badge-royal {
color: #fff;
background-color: #8a6de9
}
.uni-badge-purple.uni-badge-inverted,
.uni-badge-royal.uni-badge-inverted {
color: #8a6de9;
background-color: transparent
}
/*折叠面板 */
.uni-collapse-content {
height: 0;
width: 100%;
overflow: hidden;
}
.uni-collapse-content.uni-active {
height: auto;
}
/*卡片视图 */
.uni-card {
background: #fff;
border-radius: 8rpx;
margin:20rpx 0;
position: relative;
box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, .3);
}
.uni-card-content {
font-size: 30rpx;
}
.uni-card-content.image-view{
width: 100%;
margin: 0;
}
.uni-card-content-inner {
position: relative;
padding: 30rpx;
}
.uni-card-footer,
.uni-card-header {
position: relative;
display: flex;
min-height: 50rpx;
padding: 20rpx 30rpx;
justify-content: space-between;
align-items: center;
}
.uni-card-header {
font-size: 36rpx;
}
.uni-card-footer {
color: #6d6d72;
}
.uni-card-footer:before,
.uni-card-header:after {
position: absolute;
top: 0;
right: 0;
left: 0;
height: 2rpx;
content: '';
-webkit-transform: scaleY(.5);
transform: scaleY(.5);
background-color: #c8c7cc;
}
.uni-card-header:after {
top: auto;
bottom: 0;
}
.uni-card-media {
justify-content: flex-start;
}
.uni-card-media-logo {
height: 84rpx;
width: 84rpx;
margin-right: 20rpx;
}
.uni-card-media-body {
height: 84rpx;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: flex-start;
}
.uni-card-media-text-top {
line-height: 36rpx;
font-size: 34rpx;
}
.uni-card-media-text-bottom {
line-height: 30rpx;
font-size: 28rpx;
color: #8f8f94;
}
.uni-card-link {
color: #007AFF;
}
/* 列表 */
.uni-list {
background-color: #FFFFFF;
position: relative;
width: 100%;
display: flex;
flex-direction: column;
}
.uni-list:after {
position: absolute;
z-index: 10;
right: 0;
bottom: 0;
left: 0;
height: 1px;
content: '';
-webkit-transform: scaleY(.5);
transform: scaleY(.5);
background-color: #c8c7cc;
}
.uni-list::before {
position: absolute;
z-index: 10;
right: 0;
top: 0;
left: 0;
height: 1px;
content: '';
-webkit-transform: scaleY(.5);
transform: scaleY(.5);
background-color: #c8c7cc;
}
.uni-list-cell {
position: relative;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.uni-list-cell-hover {
background-color: #eee;
}
.uni-list-cell-pd {
padding: 22rpx 30rpx;
}
.uni-list-cell-left {
white-space: nowrap;
font-size:28rpx;
padding: 0 30rpx;
}
.uni-list-cell-db,
.uni-list-cell-right {
flex: 1;
}
.uni-list-cell::after {
position: absolute;
z-index: 3;
right: 0;
bottom: 0;
left: 30rpx;
height: 1px;
content: '';
-webkit-transform: scaleY(.5);
transform: scaleY(.5);
background-color: #c8c7cc;
}
.uni-list .uni-list-cell:last-child::after {
height: 0rpx;
}
.uni-list-cell-last.uni-list-cell::after {
height: 0rpx;
}
.uni-list-cell-divider {
position: relative;
display: flex;
color: #999;
background-color: #f7f7f7;
padding:15rpx 20rpx;
}
.uni-list-cell-divider::before {
position: absolute;
right: 0;
top: 0;
left: 0;
height: 1px;
content: '';
-webkit-transform: scaleY(.5);
transform: scaleY(.5);
background-color: #c8c7cc;
}
.uni-list-cell-divider::after {
position: absolute;
right: 0;
bottom: 0;
left: 0rpx;
height: 1px;
content: '';
-webkit-transform: scaleY(.5);
transform: scaleY(.5);
background-color: #c8c7cc;
}
.uni-list-cell-navigate {
font-size:30rpx;
padding: 22rpx 30rpx;
line-height: 48rpx;
position: relative;
display: flex;
box-sizing: border-box;
width: 100%;
flex: 1;
justify-content: space-between;
align-items: center;
}
.uni-list-cell-navigate {
padding-right: 36rpx;
}
.uni-navigate-badge {
padding-right: 50rpx;
}
.uni-list-cell-navigate.uni-navigate-right:after {
font-family: uniicons;
content: '\e583';
position: absolute;
right: 24rpx;
top: 50%;
color: #bbb;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.uni-list-cell-navigate.uni-navigate-bottom:after {
font-family: uniicons;
content: '\e581';
position: absolute;
right: 24rpx;
top: 50%;
color: #bbb;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.uni-list-cell-navigate.uni-navigate-bottom.uni-active::after {
font-family: uniicons;
content: '\e580';
position: absolute;
right: 24rpx;
top: 50%;
color: #bbb;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.uni-collapse.uni-list-cell {
flex-direction: column;
}
.uni-list-cell-navigate.uni-active {
background: #eee;
}
.uni-list.uni-collapse {
box-sizing: border-box;
height: 0;
overflow: hidden;
}
.uni-collapse .uni-list-cell {
padding-left: 20rpx;
}
.uni-collapse .uni-list-cell::after {
left: 52rpx;
}
.uni-list.uni-active {
height: auto;
}
/* 三行列表 */
.uni-triplex-row {
display: flex;
flex: 1;
width: 100%;
box-sizing: border-box;
flex-direction: row;
padding: 22rpx 30rpx;
}
.uni-triplex-right,
.uni-triplex-left {
display: flex;
flex-direction: column;
}
.uni-triplex-left {
width: 84%;
}
.uni-triplex-left .uni-title{
padding:8rpx 0;
}
.uni-triplex-left .uni-text, .uni-triplex-left .uni-text-small{color:#999999;}
.uni-triplex-right {
width: 16%;
text-align: right;
}
/* 图文列表 */
.uni-media-list {
padding: 22rpx 30rpx;
box-sizing: border-box;
display: flex;
width: 100%;
flex-direction: row;
}
.uni-navigate-right.uni-media-list {
padding-right: 74rpx;
}
.uni-pull-right {
flex-direction: row-reverse;
}
.uni-pull-right>.uni-media-list-logo {
margin-right: 0rpx;
margin-left: 20rpx;
}
.uni-media-list-logo {
height: 84rpx;
width: 84rpx;
margin-right: 20rpx;
}
.uni-media-list-logo image {
height: 100%;
width: 100%;
}
.uni-media-list-body {
height: 84rpx;
display: flex;
flex: 1;
flex-direction: column;
justify-content: space-between;
align-items: flex-start;
overflow: hidden;
}
.uni-media-list-text-top {
width: 100%;
line-height: 36rpx;
font-size: 30rpx;
}
.uni-media-list-text-bottom {
width: 100%;
line-height: 30rpx;
font-size: 26rpx;
color: #8f8f94;
}
/* 九宫格 */
.uni-grid-9 {
background: #f2f2f2;
width: 750rpx;
display: flex;
flex-direction: row;
flex-wrap: wrap;
border-top: 2rpx solid #eee;
}
.uni-grid-9-item {
width: 250rpx;
height: 200rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border-bottom: 2rpx solid;
border-right: 2rpx solid;
border-color: #eee;
box-sizing: border-box;
}
.no-border-right {
border-right: none;
}
.uni-grid-9-image {
width: 100rpx;
height: 100rpx;
}
.uni-grid-9-text {
width: 250rpx;
line-height: 4rpx;
height: 40rpx;
text-align: center;
font-size: 30rpx;
}
.uni-grid-9-item-hover {
background: rgba(0, 0, 0, 0.1);
}
/* 上传 */
.uni-uploader {
flex: 1;
flex-direction: column;
}
.uni-uploader-head {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.uni-uploader-info {
color: #B2B2B2;
}
.uni-uploader-body {
margin-top: 16rpx;
}
.uni-uploader__files {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.uni-uploader__file {
margin: 10rpx;
width: 210rpx;
height: 210rpx;
}
.uni-uploader__img {
display: block;
width: 210rpx;
height: 210rpx;
}
.uni-uploader__input-box {
position: relative;
margin:10rpx;
width: 208rpx;
height: 208rpx;
border: 2rpx solid #D9D9D9;
}
.uni-uploader__input-box:before,
.uni-uploader__input-box:after {
content: " ";
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
background-color: #D9D9D9;
}
.uni-uploader__input-box:before {
width: 4rpx;
height: 79rpx;
}
.uni-uploader__input-box:after {
width: 79rpx;
height: 4rpx;
}
.uni-uploader__input-box:active {
border-color: #999999;
}
.uni-uploader__input-box:active:before,
.uni-uploader__input-box:active:after {
background-color: #999999;
}
.uni-uploader__input {
position: absolute;
z-index: 1;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
}
/*问题反馈*/
.feedback-title {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 20rpx;
color: #8f8f94;
font-size: 28rpx;
}
.feedback-star-view.feedback-title {
justify-content: flex-start;
margin: 0;
}
.feedback-quick {
position: relative;
padding-right: 40rpx;
}
.feedback-quick:after {
font-family: uniicons;
font-size: 40rpx;
content: '\e581';
position: absolute;
right: 0;
top: 50%;
color: #bbb;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.feedback-body {
background: #fff;
}
.feedback-textare {
height: 200rpx;
font-size: 34rpx;
line-height: 50rpx;
width: 100%;
box-sizing: border-box;
padding: 20rpx 30rpx 0;
}
.feedback-input {
font-size: 34rpx;
height: 50rpx;
min-height: 50rpx;
padding: 15rpx 20rpx;
line-height: 50rpx;
}
.feedback-uploader {
padding: 22rpx 20rpx;
}
.feedback-star {
font-family: uniicons;
font-size: 40rpx;
margin-left: 6rpx;
}
.feedback-star-view {
margin-left: 20rpx;
}
.feedback-star:after {
content: '\e408';
}
.feedback-star.active {
color: #FFB400;
}
.feedback-star.active:after {
content: '\e438';
}
.feedback-submit {
background: #007AFF;
color: #FFFFFF;
margin: 20rpx;
}
/* input group */
.uni-input-group {
position: relative;
padding: 0;
border: 0;
background-color: #fff;
}
.uni-input-group:before {
position: absolute;
top: 0;
right: 0;
left: 0;
height: 2rpx;
content: '';
transform: scaleY(.5);
background-color: #c8c7cc;
}
.uni-input-group:after {
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 2rpx;
content: '';
transform: scaleY(.5);
background-color: #c8c7cc;
}
.uni-input-row {
position: relative;
display: flex;
flex-direction: row;
font-size:28rpx;
padding: 22rpx 30rpx;
justify-content: space-between;
}
.uni-input-group .uni-input-row:after {
position: absolute;
right: 0;
bottom: 0;
left: 30rpx;
height: 2rpx;
content: '';
transform: scaleY(.5);
background-color: #c8c7cc;
}
.uni-input-row label {
line-height: 70rpx;
}
/* textarea */
.uni-textarea{
width:100%;
background:#FFF;
}
.uni-textarea textarea{
width:96%;
padding:18rpx 2%;
line-height:1.6;
font-size:28rpx;
height:150rpx;
}
/* tab bar */
.uni-tab-bar {
display: flex;
flex: 1;
flex-direction: column;
overflow: hidden;
height: 100%;
}
.uni-tab-bar .list {
width: 750rpx;
height: 100%;
}
.uni-swiper-tab {
width: 100%;
white-space: nowrap;
line-height: 100rpx;
height: 100rpx;
border-bottom: 1px solid #c8c7cc;
}
.swiper-tab-list {
font-size: 30rpx;
width: 150rpx;
display: inline-block;
text-align: center;
color: #555;
}
.uni-tab-bar .active {
color: #007AFF;
}
.uni-tab-bar .swiper-box {
flex: 1;
width: 100%;
height: calc(100% - 100rpx);
}
.uni-tab-bar-loading{
padding:20rpx 0;
}
/* comment */
.uni-comment{padding:5rpx 0; display: flex; flex-grow:1; flex-direction: column;}
.uni-comment-list{flex-wrap:nowrap; padding:10rpx 0; margin:10rpx 0; width:100%; display: flex;}
.uni-comment-face{width:70rpx; height:70rpx; border-radius:100%; margin-right:20rpx; flex-shrink:0; overflow:hidden;}
.uni-comment-face image{width:100%; border-radius:100%;}
.uni-comment-body{width:100%;}
.uni-comment-top{line-height:1.5em; justify-content:space-between;}
.uni-comment-top text{color:#0A98D5; font-size:24rpx;}
.uni-comment-date{line-height:38rpx; flex-direction:row; justify-content:space-between; display:flex !important; flex-grow:1;}
.uni-comment-date view{color:#666666; font-size:24rpx; line-height:38rpx;}
.uni-comment-content{line-height:1.6em; font-size:28rpx; padding:8rpx 0;}
.uni-comment-replay-btn{background:#FFF; font-size:24rpx; line-height:28rpx; padding:5rpx 20rpx; border-radius:30rpx; color:#333 !important; margin:0 10rpx;}
/* swiper msg */
.uni-swiper-msg{width:100%; padding:12rpx 0; flex-wrap:nowrap; display:flex;}
.uni-swiper-msg-icon{width:50rpx; margin-right:20rpx;}
.uni-swiper-msg-icon image{width:100%; flex-shrink:0;}
.uni-swiper-msg swiper{width:100%; height:50rpx;}
.uni-swiper-msg swiper-item{line-height:50rpx;}
/* product */
.uni-product-list {
display: flex;
width: 100%;
flex-wrap: wrap;
flex-direction: row;
}
.uni-product {
padding: 20rpx;
display: flex;
flex-direction: column;
}
.image-view {
height: 330rpx;
width: 330rpx;
margin:12rpx 0;
}
.uni-product-image {
height: 330rpx;
width: 330rpx;
}
.uni-product-title {
width: 300rpx;
word-break: break-all;
display: -webkit-box;
overflow: hidden;
line-height:1.5;
text-overflow: ellipsis;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
.uni-product-price {
margin-top:10rpx;
font-size: 28rpx;
line-height:1.5;
position: relative;
}
.uni-product-price-original {
color: #e80080;
}
.uni-product-price-favour {
color: #888888;
text-decoration: line-through;
margin-left: 10rpx;
}
.uni-product-tip {
position: absolute;
right: 10rpx;
background-color: #ff3333;
color: #ffffff;
padding: 0 10rpx;
border-radius: 5rpx;
}
/* timeline */
.uni-timeline {
margin: 35rpx 0;
display: flex;
flex-direction: column;
position: relative;
}
.uni-timeline-item {
display: flex;
flex-direction: row;
position: relative;
padding-bottom: 20rpx;
box-sizing: border-box;
overflow: hidden;
}
.uni-timeline-item .uni-timeline-item-keynode {
width: 160rpx;
flex-shrink: 0;
box-sizing: border-box;
padding-right: 20rpx;
text-align: right;
line-height: 65rpx;
}
.uni-timeline-item .uni-timeline-item-divider {
flex-shrink: 0;
position: relative;
width: 30rpx;
height: 30rpx;
top: 15rpx;
border-radius: 50%;
background-color: #bbb;
}
.uni-timeline-item-divider::before,
.uni-timeline-item-divider::after {
position: absolute;
left: 15rpx;
width: 1rpx;
height: 100vh;
content: '';
background: inherit;
}
.uni-timeline-item-divider::before {
bottom: 100%;
}
.uni-timeline-item-divider::after {
top: 100%;
}
.uni-timeline-last-item .uni-timeline-item-divider:after {
display: none;
}
.uni-timeline-first-item .uni-timeline-item-divider:before {
display: none;
}
.uni-timeline-item .uni-timeline-item-content {
padding-left: 20rpx;
}
.uni-timeline-last-item .bottom-border::after{
display: none;
}
.uni-timeline-item-content .datetime{
color: #CCCCCC;
}
/* 自定义节点颜色 */
.uni-timeline-last-item .uni-timeline-item-divider{
background-color: #1AAD19;
}
/* uni-icon */
.uni-icon {
font-family: uniicons;
font-size: 24px;
font-weight: normal;
font-style: normal;
line-height: 1;
display: inline-block;
text-decoration: none;
-webkit-font-smoothing: antialiased;
}
.uni-icon.uni-active {
color: #007aff;
}
.uni-icon-contact:before {
content: '\e100';
}
.uni-icon-person:before {
content: '\e101';
}
.uni-icon-personadd:before {
content: '\e102';
}
.uni-icon-contact-filled:before {
content: '\e130';
}
.uni-icon-person-filled:before {
content: '\e131';
}
.uni-icon-personadd-filled:before {
content: '\e132';
}
.uni-icon-phone:before {
content: '\e200';
}
.uni-icon-email:before {
content: '\e201';
}
.uni-icon-chatbubble:before {
content: '\e202';
}
.uni-icon-chatboxes:before {
content: '\e203';
}
.uni-icon-phone-filled:before {
content: '\e230';
}
.uni-icon-email-filled:before {
content: '\e231';
}
.uni-icon-chatbubble-filled:before {
content: '\e232';
}
.uni-icon-chatboxes-filled:before {
content: '\e233';
}
.uni-icon-weibo:before {
content: '\e260';
}
.uni-icon-weixin:before {
content: '\e261';
}
.uni-icon-pengyouquan:before {
content: '\e262';
}
.uni-icon-chat:before {
content: '\e263';
}
.uni-icon-qq:before {
content: '\e264';
}
.uni-icon-videocam:before {
content: '\e300';
}
.uni-icon-camera:before {
content: '\e301';
}
.uni-icon-mic:before {
content: '\e302';
}
.uni-icon-location:before {
content: '\e303';
}
.uni-icon-mic-filled:before,
.uni-icon-speech:before {
content: '\e332';
}
.uni-icon-location-filled:before {
content: '\e333';
}
.uni-icon-micoff:before {
content: '\e360';
}
.uni-icon-image:before {
content: '\e363';
}
.uni-icon-map:before {
content: '\e364';
}
.uni-icon-compose:before {
content: '\e400';
}
.uni-icon-trash:before {
content: '\e401';
}
.uni-icon-upload:before {
content: '\e402';
}
.uni-icon-download:before {
content: '\e403';
}
.uni-icon-close:before {
content: '\e404';
}
.uni-icon-redo:before {
content: '\e405';
}
.uni-icon-undo:before {
content: '\e406';
}
.uni-icon-refresh:before {
content: '\e407';
}
.uni-icon-star:before {
content: '\e408';
}
.uni-icon-plus:before {
content: '\e409';
}
.uni-icon-minus:before {
content: '\e410';
}
.uni-icon-circle:before,
.uni-icon-checkbox:before {
content: '\e411';
}
.uni-icon-close-filled:before,
.uni-icon-clear:before {
content: '\e434';
}
.uni-icon-refresh-filled:before {
content: '\e437';
}
.uni-icon-star-filled:before {
content: '\e438';
}
.uni-icon-plus-filled:before {
content: '\e439';
}
.uni-icon-minus-filled:before {
content: '\e440';
}
.uni-icon-circle-filled:before {
content: '\e441';
}
.uni-icon-checkbox-filled:before {
content: '\e442';
}
.uni-icon-closeempty:before {
content: '\e460';
}
.uni-icon-refreshempty:before {
content: '\e461';
}
.uni-icon-reload:before {
content: '\e462';
}
.uni-icon-starhalf:before {
content: '\e463';
}
.uni-icon-spinner:before {
content: '\e464';
}
.uni-icon-spinner-cycle:before {
content: '\e465';
}
.uni-icon-search:before {
content: '\e466';
}
.uni-icon-plusempty:before {
content: '\e468';
}
.uni-icon-forward:before {
content: '\e470';
}
.uni-icon-back:before,
.uni-icon-left-nav:before {
content: '\e471';
}
.uni-icon-checkmarkempty:before {
content: '\e472';
}
.uni-icon-home:before {
content: '\e500';
}
.uni-icon-navigate:before {
content: '\e501';
}
.uni-icon-gear:before {
content: '\e502';
}
.uni-icon-paperplane:before {
content: '\e503';
}
.uni-icon-info:before {
content: '\e504';
}
.uni-icon-help:before {
content: '\e505';
}
.uni-icon-locked:before {
content: '\e506';
}
.uni-icon-more:before {
content: '\e507';
}
.uni-icon-flag:before {
content: '\e508';
}
.uni-icon-home-filled:before {
content: '\e530';
}
.uni-icon-gear-filled:before {
content: '\e532';
}
.uni-icon-info-filled:before {
content: '\e534';
}
.uni-icon-help-filled:before {
content: '\e535';
}
.uni-icon-more-filled:before {
content: '\e537';
}
.uni-icon-settings:before {
content: '\e560';
}
.uni-icon-list:before {
content: '\e562';
}
.uni-icon-bars:before {
content: '\e563';
}
.uni-icon-loop:before {
content: '\e565';
}
.uni-icon-paperclip:before {
content: '\e567';
}
.uni-icon-eye:before {
content: '\e568';
}
.uni-icon-arrowup:before {
content: '\e580';
}
.uni-icon-arrowdown:before {
content: '\e581';
}
.uni-icon-arrowleft:before {
content: '\e582';
}
.uni-icon-arrowright:before {
content: '\e583';
}
.uni-icon-arrowthinup:before {
content: '\e584';
}
.uni-icon-arrowthindown:before {
content: '\e585';
}
.uni-icon-arrowthinleft:before {
content: '\e586';
}
.uni-icon-arrowthinright:before {
content: '\e587';
}
.uni-icon-pulldown:before {
content: '\e588';
}
.uni-icon-scan:before {
content: "\e612";
}
/* 分界线 */
.uni-divider{
height: 110rpx;
display: flex;
align-items:center;
justify-content: center;
position: relative;
}
.uni-divider__content{
font-size: 28rpx;
color: #999;
padding: 0 20rpx;
position: relative;
z-index: 101;
background: #F4F5F6;
}
.uni-divider__line{
background-color: #CCCCCC;
height: 1px;
width: 100%;
position: absolute;
z-index: 100;
top: 50%;
left: 0;
transform: translateY(50%);
}
<template>
<uni-popup ref="popup" type="center" :maskClick="false">
<view class="update-wrap">
<view class="white-bg"></view>
<image src="@/static/images/top_2.png" class="updateCon-img"></image>
<view class="updateCon-top">
<!-- 发现新版本 -->
<text class="update-top-title">发现新版本</text>
<text class="update-top-version">V{{update_info.version}}</text>
</view>
<text class="uodate-content" v-if="!update_ing">更新内容:{{update_info.version_note}}</text>
<text class="current-version" v-if="!update_ing">当前版本:V{{version}}</text>
<view class="update-btn" v-if="!update_ing">
<view class="update-btn-item update-btn-left" @click="up_close">
<!-- 残忍拒绝 -->
<text class="update-btn-item-text ">残忍拒绝</text>
</view>
<view class="update-btn-item" @click="nowUpdate">
<!-- 立即升级 -->
<text class="update-btn-item-text text-bule">立即升级</text>
</view>
</view>
<!-- 下载进度 -->
<view class="sche-wrap" v-if="update_ing">
<!-- 更新包下载中 -->
<text class="sche-wrap-text">更新包下载中...</text>
<view class="sche-bg">
<view class="sche-bg-jindu" :style="lengthWidth">
<view class="sche-bg-round">
<text class="sche-bg-round-text" v-if="schedule">{{schedule}}%</text>
<text class="sche-bg-round-text" v-else>{{(downloadedSize/1024/1024 ).toFixed(2)}}M</text>
</view>
</view>
</view>
</view>
</view>
</uni-popup>
</template>
<script>
import uniPopup from '@/components/uni-popup/uni-popup.vue'
export default {
data() {
return {
platform: "", //ios or android
version: "1.0.0", //当前软件版本
is_update: false, // 是否更新
is_reques: false, //是否请求中
update_info: {
"type": "1", //1分发平台更新 2安装包/升级包更新
"version_note": "", //ios更新备注
"version": "1.0.0", //ios版本号
"download_url": "", //ios更新新链接
},
is_update: false,
schedule: 0,
update_ing: false, //点击升级
is_down: false,
downloadedSize: 0,
};
},
components:{uniPopup},
mounted() {
this.getSystemInfo() //获取系统新
},
computed: {
// 下载进度计算
lengthWidth: function() {
return {
width: this.schedule * 480 / 100 + "rpx"
}
}
},
methods: {
// 获取系统信息
getSystemInfo() {
let vm = this;
// 获取手机系统信息
uni.getSystemInfo({
success: function(res) {
vm.platform = res.platform //ios or android
}
});
// 获取版本号
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
vm.version = inf.version
});
vm.getUpdateInfo(); //获取更新信息
},
// 获取线上版本信息
getUpdateInfo() {
let vm = this;
uni.request({
url: 'http://ui.ishenghuo.org.cn/api/version.php', //仅为示例,并非真实接口地址。
success: (res) => {
let data = res.data.data;
if (vm.platform == "ios") {
vm.update_info.type = data.ios_type
vm.update_info.version_note = data.ios_version_note
vm.update_info.version = data.ios_version
vm.update_info.download_url = data.ios_download_url
} else if (vm.platform == "android") {
vm.update_info.type = data.android_type
vm.update_info.version_note = data.android_version_note
vm.update_info.version = data.android_version
vm.update_info.download_url = data.android_download_url
} else {
return false
}
vm.checkUpdate(); ///检查是否更新
}
});
},
// 检查是否更新
checkUpdate() {
let vm = this;
vm.is_update = vm.compareVersion(vm.version, vm.update_info.version); // 检查是否升级
if (vm.is_update) {
vm.$refs.popup.open() //显示升级弹窗
} else {
// 不更新,根据需要做处理
}
},
// 取消更新
up_close() {
// console.log('点击取消')
plus.os.name == "Android" ? plus.runtime.quit() : plus.ios.import("UIApplication").sharedApplication().performSelector("exit");
},
// 立即更新
nowUpdate() {
let vm = this;
if(vm.is_reques){
return false //如果正在下载就停止操作
}else{
vm.is_reques = true
}
console.log(111111);
if (vm.update_info.type == 1) {
// 分发平台更新 //调用浏览器打开链接或者分发平台
plus.runtime.openURL(vm.update_info.download_url, function() {
plus.nativeUI.toast("打开错误");
});
setTimeout(function() {
plus.runtime.quit(); //五秒后关闭app
}, 5000)
} else if (vm.update_info.type == 2) {
// 安装包/升级包更新
vm.download_wgt()
}
},
// 下载升级资源包
download_wgt() {
let vm = this;
plus.nativeUI.showWaiting("下载更新文件..."); //下载更新文件...
let options = {
method: "POST"
};
let dtask = plus.downloader.createDownload(vm.update_info.download_url, options);
dtask.addEventListener("statechanged", function(task, status) {
switch (task.state) {
case 1: // 开始
break;
case 2: //已连接到服务器
vm.update_ing = true;
break;
case 3: // 已接收到数据
vm.downloadedSize = task.downloadedSize;
let totalSize = 0;
if (task.totalSize) {
totalSize = task.totalSize //服务器须返回正确的content-length才会有长度
}
vm.schedule = parseInt(100 * task.downloadedSize / totalSize);
break;
case 4:
vm.installWgt(task.filename); // 安装wgt包
break;
}
});
dtask.start();
},
// 安装文件
installWgt(path) {
let vm = this;
plus.nativeUI.showWaiting("安装更新文件..."); //安装更新文件...
plus.runtime.install(path, {}, function() {
plus.nativeUI.closeWaiting();
// 应用资源更新完成!
plus.nativeUI.alert("应用资源更新完成!", function() {
plus.runtime.restart();
});
}, function(e) {
plus.nativeUI.closeWaiting();
// 安装更新文件失败
plus.nativeUI.alert("安装更新文件失败[" + e.code + "]:" + e.message);
});
},
// 对比版本号
compareVersion(ov, nv) {
if (!ov || !nv || ov == "" || nv == "") {
return false;
}
let b = false,
ova = ov.split(".", 4),
nva = nv.split(".", 4);
for (let i = 0; i < ova.length && i < nva.length; i++) {
let so = ova[i],
no = parseInt(so),
sn = nva[i],
nn = parseInt(sn);
if (nn > no || sn.length > so.length) {
return true;
} else if (nn < no) {
return false;
}
}
if (nva.length > ova.length && 0 == nv.indexOf(ov)) {
return true;
} else {
return false;
}
},
}
}
</script>
<style scoped>
/*#ifndef APP-NVUE*/
view {
display: flex;
flex-direction: column;
box-sizing: border-box;
}
/*#endif*/
.updateBox {
background-color: rgba(0, 0, 0, 0.6);
z-index: 1000;
position: fixed;
right: 0px;
top: 0;
left: 0;
bottom: 0;
align-items: center;
justify-content: center;
}
.update-wrap {
width: 580rpx;
height: 500rpx;
border-radius: 10px;
padding-bottom: 0px;
position: relative;
}
.white-bg {
position: absolute;
top: 60rpx;
left: 0px;
width: 580rpx;
height: 440rpx;
background-color: #ffffff;
border-bottom-left-radius: 30rpx;
border-bottom-right-radius: 30rpx;
}
.updateCon-img {
position: absolute;
top: 0rpx;
left: 0px;
width: 580rpx;
height: 440rpx;
}
.updateCon-top {
padding: 70rpx 50rpx;
/*#ifndef APP-NVUE*/
z-index: 1;
/*#endif*/
}
.update-top-title {
color: #fff;
font-size: 36rpx;
font-weight: bold;
}
.update-top-version {
color: #fff;
font-size: 28rpx;
margin-top: 10rpx;
}
.uodate-content {
color: #333;
font-size: 18px;
padding: 0px 50rpx;
margin-top: 80rpx;
/*#ifndef APP-NVUE*/
z-index: 1;
/*#endif*/
}
.current-version {
text-align: center;
margin-top: 10rpx;
font-size: 24rpx;
color: #666;
/*#ifndef APP-NVUE*/
z-index: 1;
/*#endif*/
}
.update-btn {
position: absolute;
left: 0px;
bottom: 0px;
width: 580rpx;
height: 80rpx;
padding: 0px 50rpx;
align-items: center;
flex-direction: row;
border-top-color: #e7e7e7;
border-top-style: solid;
border-top-width: 1px;
background-color: #fff;
border-bottom-left-radius: 30rpx;
border-bottom-right-radius: 30rpx;
}
.update-btn-item {
width: 240rpx;
height: 80rpx;
justify-content: center;
align-items: center;
}
.update-btn-left {
border-right-color: #e7e7e7;
border-right-style: solid;
border-right-width: 1px;
}
.update-btn-item-text {
text-align: center;
font-size: 28rpx;
color: #666;
}
.text-bule {
color: #045FCF;
}
.sche-wrap {
padding: 0px 50rpx 0rpx;
height: 100rpx;
align-items: center;
border-bottom-left-radius: 30rpx;
border-bottom-right-radius: 30rpx;
flex: 1;
justify-content: flex-end;
}
.sche-wrap-text {
font-size: 24rpx;
color: #666;
margin-bottom: 20rpx;
}
.sche-bg {
position: relative;
background-color: #ccc;
height: 20rpx;
border-radius: 100px;
width: 480rpx;
margin-bottom: 30rpx;
}
.sche-bg-jindu {
position: absolute;
left: 0px;
top: 0px;
height: 20rpx;
background-color: #5775e7;
border-radius: 100px;
}
.sche-bg-round {
position: absolute;
left: 100%;
height: 24rpx;
width: 24rpx;
background-color: #fff;
border-color: #fff;
border-style: solid;
border-width: 10px;
border-radius: 100px;
transform: translateX(-20rpx) translateY(-10rpx);
}
.sche-bg-round-text {
font-size: 24rpx;
width: 120rpx;
text-align: center;
transform: translateX(-50rpx) translateY(-40rpx);
color: #5775e7;
}
.uodate-close {
/* display: flex; */
flex-direction: row;
justify-content: center;
padding-top: 50rpx;
}
.uodate-close-img {
width: 80rpx;
height: 80rpx;
}
</style>
export default {
created() {
if (this.type === 'message') {
// 不显示遮罩
this.maskShow = false
// 获取子组件对象
this.childrenMsg = null
}
},
methods: {
customOpen() {
if (this.childrenMsg) {
this.childrenMsg.open()
}
},
customClose() {
if (this.childrenMsg) {
this.childrenMsg.close()
}
}
}
}
import message from './message.js';
// 定义 type 类型:弹出类型:top/bottom/center
const config = {
// 顶部弹出
top:'top',
// 底部弹出
bottom:'bottom',
// 居中弹出
center:'center',
// 消息提示
message:'top',
// 对话框
dialog:'center',
// 分享
share:'bottom',
}
export default {
data(){
return {
config:config
}
},
mixins: [message]
}
export default {
created() {
if (this.type === 'share') {
// 关闭点击
this.mkclick = false
}
},
methods: {
customOpen() {
console.log('share 打开了');
},
customClose() {
console.log('share 关闭了');
}
}
}
<template>
<view v-if="showPopup" class="uni-popup" :class="[popupstyle]" @touchmove.stop.prevent="clear">
<uni-transition v-if="maskShow" class="uni-mask--hook" :mode-class="['fade']" :styles="maskClass" :duration="duration" :show="showTrans" @click="onTap" />
<uni-transition :mode-class="ani" :styles="transClass" :duration="duration" :show="showTrans" @click="onTap">
<view class="uni-popup__wrapper-box" @click.stop="clear">
<slot />
</view>
</uni-transition>
</view>
</template>
<script>
import uniTransition from '../uni-transition/uni-transition.vue'
import popup from './popup.js'
/**
* PopUp 弹出层
* @description 弹出层组件,为了解决遮罩弹层的问题
* @tutorial https://ext.dcloud.net.cn/plugin?id=329
* @property {String} type = [top|center|bottom] 弹出方式
* @value top 顶部弹出
* @value center 中间弹出
* @value bottom 底部弹出
* @value message 消息提示
* @value dialog 对话框
* @value share 底部分享示例
* @property {Boolean} animation = [ture|false] 是否开启动画
* @property {Boolean} maskClick = [ture|false] 蒙版点击是否关闭弹窗
* @event {Function} change 打开关闭弹窗触发,e={show: false}
*/
export default {
name: 'UniPopup',
components: {
uniTransition
},
props: {
// 开启动画
animation: {
type: Boolean,
default: true
},
// 弹出层类型,可选值,top: 顶部弹出层;bottom:底部弹出层;center:全屏弹出层
// message: 消息提示 ; dialog : 对话框
type: {
type: String,
default: 'center'
},
// maskClick
maskClick: {
type: Boolean,
default: true
}
},
provide() {
return {
popup: this
}
},
mixins: [popup],
watch: {
/**
* 监听type类型
*/
type: {
handler: function(newVal) {
this[this.config[newVal]]()
},
immediate: true
},
/**
* 监听遮罩是否可点击
* @param {Object} val
*/
maskClick: {
handler: function(val) {
this.mkclick = val
},
immediate: true
}
},
data() {
return {
duration: 300,
ani: [],
showPopup: false,
showTrans: false,
maskClass: {
'position': 'fixed',
'bottom': 0,
'top': 0,
'left': 0,
'right': 0,
'backgroundColor': 'rgba(0, 0, 0, 0.4)'
},
transClass: {
'position': 'fixed',
'left': 0,
'right': 0,
},
maskShow: true,
mkclick: true,
popupstyle: 'top'
}
},
created() {
this.mkclick = this.maskClick
if (this.animation) {
this.duration = 300
} else {
this.duration = 0
}
},
methods: {
clear(e) {
// TODO nvue 取消冒泡
e.stopPropagation()
},
open() {
this.showPopup = true
this.$nextTick(() => {
new Promise(resolve => {
clearTimeout(this.timer)
this.timer = setTimeout(() => {
this.showTrans = true
// fixed by mehaotian 兼容 app 端
this.$nextTick(() => {
resolve();
})
}, 50);
}).then(res => {
// 自定义打开事件
clearTimeout(this.msgtimer)
this.msgtimer = setTimeout(() => {
this.customOpen && this.customOpen()
}, 100)
this.$emit('change', {
show: true,
type: this.type
})
})
})
},
close(type) {
this.showTrans = false
this.$nextTick(() => {
this.$emit('change', {
show: false,
type: this.type
})
clearTimeout(this.timer)
// 自定义关闭事件
this.customOpen && this.customClose()
this.timer = setTimeout(() => {
this.showPopup = false
}, 300)
})
},
onTap() {
if (!this.mkclick) return
this.close()
},
/**
* 顶部弹出样式处理
*/
top() {
this.popupstyle = 'top'
this.ani = ['slide-top']
this.transClass = {
'position': 'fixed',
'left': 0,
'right': 0,
}
},
/**
* 底部弹出样式处理
*/
bottom() {
this.popupstyle = 'bottom'
this.ani = ['slide-bottom']
this.transClass = {
'position': 'fixed',
'left': 0,
'right': 0,
'bottom': 0
}
},
/**
* 中间弹出样式处理
*/
center() {
this.popupstyle = 'center'
this.ani = ['zoom-out', 'fade']
this.transClass = {
'position': 'fixed',
/* #ifndef APP-NVUE */
'display': 'flex',
'flexDirection': 'column',
/* #endif */
'bottom': 0,
'left': 0,
'right': 0,
'top': 0,
'justifyContent': 'center',
'alignItems': 'center'
}
}
}
}
</script>
<style scoped>
@charset "UTF-8";
.uni-popup {
position: fixed;
/* #ifndef APP-NVUE */
z-index: 99;
/* #endif */
}
.uni-popup__mask {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0, 0, 0, 0.4);
opacity: 0;
}
.mask-ani {
transition-property: opacity;
transition-duration: 0.2s;
}
.uni-top-mask {
opacity: 1;
}
.uni-bottom-mask {
opacity: 1;
}
.uni-center-mask {
opacity: 1;
}
.uni-popup__wrapper {
/* #ifndef APP-NVUE */
display: block;
/* #endif */
position: absolute;
}
.top {
/* #ifdef H5 */
top: var(--window-top);
/* #endif */
/* #ifndef H5 */
top: 0;
/* #endif */
}
.bottom {
bottom: 0;
}
.uni-popup__wrapper-box {
/* #ifndef APP-NVUE */
display: block;
/* #endif */
position: relative;
/* iphonex 等安全区设置,底部安全区适配 */
/* #ifndef APP-NVUE */
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
/* #endif */
}
.content-ani {
transition-property: transform, opacity;
transition-duration: 0.2s;
}
.uni-top-content {
transform: translateY(0);
}
.uni-bottom-content {
transform: translateY(0);
}
.uni-center-content {
transform: scale(1);
opacity: 1;
}
</style>
\ No newline at end of file
<template>
<view v-if="isShow" ref="ani" class="uni-transition" :class="[ani.in]" :style="'transform:' +transform+';'+stylesObject" @click="change">
<slot></slot>
</view>
</template>
<script>
// #ifdef APP-NVUE
const animation = uni.requireNativePlugin('animation');
// #endif
/**
* Transition 过渡动画
* @description 简单过渡动画组件
* @tutorial https://ext.dcloud.net.cn/plugin?id=985
* @property {Boolean} show = [false|true] 控制组件显示或隐藏
* @property {Array} modeClass = [fade|slide-top|slide-right|slide-bottom|slide-left|zoom-in|zoom-out] 过渡动画类型
* @value fade 渐隐渐出过渡
* @value slide-top 由上至下过渡
* @value slide-right 由右至左过渡
* @value slide-bottom 由下至上过渡
* @value slide-left 由左至右过渡
* @value zoom-in 由小到大过渡
* @value zoom-out 由大到小过渡
* @property {Number} duration 过渡动画持续时间
* @property {Object} styles 组件样式,同 css 样式,注意带’-‘连接符的属性需要使用小驼峰写法如:`backgroundColor:red`
*/
export default {
name: 'uniTransition',
props: {
show: {
type: Boolean,
default: false
},
modeClass: {
type: Array,
default () {
return []
}
},
duration: {
type: Number,
default: 300
},
styles: {
type: Object,
default () {
return {}
}
}
},
data() {
return {
isShow: false,
transform: '',
ani: {
in: '',
active: ''
}
};
},
watch: {
show: {
handler(newVal) {
if (newVal) {
this.open()
} else {
this.close()
}
},
immediate: true
}
},
computed: {
stylesObject() {
let styles = {
...this.styles,
'transition-duration': this.duration / 1000 + 's'
}
let transfrom = ''
for (let i in styles) {
let line = this.toLine(i)
transfrom += line + ':' + styles[i] + ';'
}
return transfrom
}
},
created() {
// this.timer = null
// this.nextTick = (time = 50) => new Promise(resolve => {
// clearTimeout(this.timer)
// this.timer = setTimeout(resolve, time)
// return this.timer
// });
},
methods: {
change() {
this.$emit('click', {
detail: this.isShow
})
},
open() {
clearTimeout(this.timer)
this.isShow = true
this.transform = ''
this.ani.in = ''
for (let i in this.getTranfrom(false)) {
if (i === 'opacity') {
this.ani.in = 'fade-in'
} else {
this.transform += `${this.getTranfrom(false)[i]} `
}
}
this.$nextTick(() => {
setTimeout(() => {
this._animation(true)
}, 50)
})
},
close(type) {
clearTimeout(this.timer)
this._animation(false)
},
_animation(type) {
let styles = this.getTranfrom(type)
// #ifdef APP-NVUE
if (!this.$refs['ani']) return
animation.transition(this.$refs['ani'].ref, {
styles,
duration: this.duration, //ms
timingFunction: 'ease',
needLayout: false,
delay: 0 //ms
}, () => {
if (!type) {
this.isShow = false
}
this.$emit('change', {
detail: this.isShow
})
})
// #endif
// #ifndef APP-NVUE
this.transform = ''
for (let i in styles) {
if (i === 'opacity') {
this.ani.in = `fade-${type?'out':'in'}`
} else {
this.transform += `${styles[i]} `
}
}
this.timer = setTimeout(() => {
if (!type) {
this.isShow = false
}
this.$emit('change', {
detail: this.isShow
})
}, this.duration)
// #endif
},
getTranfrom(type) {
let styles = {
transform: ''
}
this.modeClass.forEach((mode) => {
switch (mode) {
case 'fade':
styles.opacity = type ? 1 : 0
break;
case 'slide-top':
styles.transform += `translateY(${type?'0':'-100%'}) `
break;
case 'slide-right':
styles.transform += `translateX(${type?'0':'100%'}) `
break;
case 'slide-bottom':
styles.transform += `translateY(${type?'0':'100%'}) `
break;
case 'slide-left':
styles.transform += `translateX(${type?'0':'-100%'}) `
break;
case 'zoom-in':
styles.transform += `scale(${type?1:0.8}) `
break;
case 'zoom-out':
styles.transform += `scale(${type?1:1.2}) `
break;
}
})
return styles
},
_modeClassArr(type) {
let mode = this.modeClass
if (typeof(mode) !== "string") {
let modestr = ''
mode.forEach((item) => {
modestr += (item + '-' + type + ',')
})
return modestr.substr(0, modestr.length - 1)
} else {
return mode + '-' + type
}
},
// getEl(el) {
// console.log(el || el.ref || null);
// return el || el.ref || null
// },
toLine(name) {
return name.replace(/([A-Z])/g, "-$1").toLowerCase();
}
}
}
</script>
<style scoped>
.uni-transition {
transition-timing-function: ease;
transition-duration: 0.3s;
transition-property: transform, opacity;
}
.fade-in {
opacity: 0;
}
.fade-active {
opacity: 1;
}
.slide-top-in {
/* transition-property: transform, opacity; */
transform: translateY(-100%);
}
.slide-top-active {
transform: translateY(0);
/* opacity: 1; */
}
.slide-right-in {
transform: translateX(100%);
}
.slide-right-active {
transform: translateX(0);
}
.slide-bottom-in {
transform: translateY(100%);
}
.slide-bottom-active {
transform: translateY(0);
}
.slide-left-in {
transform: translateX(-100%);
}
.slide-left-active {
transform: translateX(0);
opacity: 1;
}
.zoom-in-in {
transform: scale(0.8);
}
.zoom-out-active {
transform: scale(1);
}
.zoom-out-in {
transform: scale(1.2);
}
</style>
\ No newline at end of file
...@@ -52,7 +52,78 @@ ...@@ -52,7 +52,78 @@
"style":{ "style":{
"navigationBarTitleText":"注册" "navigationBarTitleText":"注册"
} }
}], },{
"path":"pages/uni-feedback/uni-feedback",
"style":{
"navigationBarTitleText":"问题反馈"
}
} ,{
"path" : "pages/about/about",
"style" :
{
"navigationBarTitleText": "关于"
}
},{
"path" : "pages/agree-list/agree-list",
"style" :
{
"navigationBarTitleText": "政策与协议"
}
}
,{
"path" : "pages/agree-list/privacy/privacy",
"style" :
{
"navigationBarTitleText": "隐私政策"
}
}
,{
"path" : "pages/agree-list/service/service",
"style" :
{
"navigationBarTitleText": "服务协议"
}
},{
"path": "uni_modules/uni-upgrade-center-app/pages/upgrade-popup",
"style": {
"disableScroll": true,
"app-plus": {
"backgroundColorTop": "transparent",
"background": "transparent",
"titleNView": false,
"scrollIndicator": false,
"popGesture": "none",
"animationType": "fade-in",
"animationDuration": 200
}
}
}
,{
"path" : "pages/settings/settings",
"style" :
{
"navigationBarTitleText": "设置"
}
}
,{
"path" : "pages/ucenter/edit/edit",
"style" :
{
"navigationBarTitleText": "编辑资料"
}
},{
"path":"pages/ucenter/edit/uploadCutImageToUnicloud",
"style":{
"navigationStyle":"custom"
}
}
],
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black",
"navigationBarTitleText": "base-app", "navigationBarTitleText": "base-app",
......
<template>
<view class="about">
<view class="content">
<view class="qrcode">
<image src="https://img.cdn.aliyun.dcloud.net.cn/guide/uniapp/app_download.png" @longtap="save"></image>
<text class="tip">扫码体验uni-app</text>
</view>
<view class="desc">
<text class="code">uni-app</text>
是一个使用 <text class="code">Vue.js</text> 开发跨平台应用的前端框架。
</view>
<view class="source">
<view class="title">本示例源码获取方式:</view>
<view class="source-list">
<view class="source-cell">
<text space="nbsp">1. </text>
<text>下载 HBuilderX,新建 uni-app 项目时选择 <text class="code">Hello uni-app</text> 模板。</text>
</view>
<view class="source-cell">
<text space="nbsp">2. </text>
<u-link class="link" :href="'https://github.com/dcloudio/hello-uniapp'" :text="'https://github.com/dcloudio/hello-uniapp'"></u-link>
</view>
</view>
</view>
<!-- #ifdef APP-PLUS -->
<button type="primary" @click="share">分享</button>
<!-- #endif -->
</view>
<!-- #ifdef APP-PLUS -->
<view class="version">
当前版本:{{version}}
</view>
<!-- #endif -->
</view>
</template>
<script>
export default {
data() {
return {
providerList: [],
version: ''
}
},
onLoad() {
// #ifdef APP-PLUS
this.version = plus.runtime.version;
uni.getProvider({
service: 'share',
success: (result) => {
const data = [];
for (let i = 0; i < result.provider.length; i++) {
switch (result.provider[i]) {
case 'weixin':
data.push({
name: '分享到微信好友',
id: 'weixin'
});
data.push({
name: '分享到微信朋友圈',
id: 'weixin',
type: 'WXSenceTimeline'
});
break;
case 'qq':
data.push({
name: '分享到QQ',
id: 'qq'
});
break;
default:
break;
}
}
this.providerList = data;
},
fail: (error) => {
console.log('获取分享通道失败' + JSON.stringify(error));
}
});
// #endif
},
methods: {
// #ifdef APP-PLUS
save() {
uni.showActionSheet({
itemList: ['保存图片到相册'],
success: () => {
plus.gallery.save('https://img.cdn.aliyun.dcloud.net.cn/guide/uniapp/app_download.png', function() {
uni.showToast({
title: '保存成功',
icon: 'none'
});
}, function() {
uni.showToast({
title: '保存失败,请重试!',
icon: 'none'
});
});
}
});
},
share(e) {
if (this.providerList.length === 0) {
uni.showModal({
title: '当前环境无分享渠道!',
showCancel: false
});
return;
}
let itemList = this.providerList.map(function(value) {
return value.name;
})
uni.showActionSheet({
itemList: itemList,
success: (res) => {
let provider = this.providerList[res.tapIndex].id;
uni.share({
provider: provider,
scene: this.providerList[res.tapIndex].type && this.providerList[res.tapIndex].type === 'WXSenceTimeline' ?
'WXSenceTimeline' : "WXSceneSession",
type: (provider === "qq") ? 1 : 0,
title: '欢迎体验uni-app',
summary: 'uni-app 是一个使用 Vue.js 开发跨平台应用的前端框架',
imageUrl: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/b09e38e0-5168-11eb-b680-7980c8a877b8.jpg',
href: "https://m3w.cn/uniapp",
success: (res) => {
console.log("success:" + JSON.stringify(res));
},
fail: (e) => {
uni.showModal({
content: e.errMsg,
showCancel: false
})
}
});
}
})
}
// #endif
}
}
</script>
<style>
page,
view {
display: flex;
}
page {
min-height: 100%;
background-color: #FFFFFF;
}
image {
width: 360rpx;
height: 360rpx;
}
.about {
flex-direction: column;
flex: 1;
}
.content {
flex: 1;
padding: 30rpx;
flex-direction: column;
justify-content: center;
}
.qrcode {
display: flex;
align-items: center;
flex-direction: column;
}
.qrcode .tip {
margin-top: 20rpx;
}
.desc {
margin-top: 30rpx;
display: block;
}
.code {
color: #e96900;
background-color: #f8f8f8;
}
button {
width: 100%;
margin-top: 40rpx;
}
.version {
height: 80rpx;
line-height: 80rpx;
justify-content: center;
color: #ccc;
}
.source {
margin-top: 30rpx;
flex-direction: column;
}
.source-list {
flex-direction: column;
}
.link {
color: #007AFF;
}
</style>
<template>
<view class="content">
<uni-list class="content">
<uni-list-item v-for="(item , index) in agreeList" :key="index" :title="item.title" :to="item.to"></uni-list-item>
</uni-list>
</view>
</template>
<script>
export default {
data() {
return {
agreeList:[
{
title:'隐私政策',
to:'./privacy/privacy'
},
{
title:'服务协议',
to:'./service/service'
}
]
}
}
}
</script>
<style>
.content{
width: 750rpx;
display: flex;
flex-direction: column;
/* align-items: center; */
flex: 1;
}
</style>
<template>
<view>
<text>隐私政策相关文本内容</text>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
<template>
<view>
<text>服务协议相关文本内容</text>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
...@@ -48,8 +48,10 @@ ...@@ -48,8 +48,10 @@
</view> </view>
</view> </view>
<view class="oauth-row" v-if="hasProvider && !hasAppleLogin && platform ==='ios'" v-bind:style="{top: (positionTop - 50) + 'px'}"> <view class="oauth-row" v-if="hasProvider && !hasAppleLogin && platform ==='ios'" v-bind:style="{top: (positionTop - 50) + 'px'}">
<text style="color: #C8C7CC;text-align: center;">暂无法使用苹果登录,请查阅&nbsp;&nbsp; <text style="color: #C8C7CC;text-align: center;font-size: 30rpx;">登录/注册即表示您同意
<text style="color: #C8C7CC;text-decoration: underline;" @click="openAppleLoginDoc">Apple登录集成教程</text> <text style="color: #C8C7CC;text-decoration: underline;" @click="toPrivacy">隐私政策</text>
<text></text>
<text style="color: #C8C7CC;text-decoration: underline;" @click="toService">服务协议</text>
</text> </text>
</view> </view>
</view> </view>
...@@ -122,6 +124,16 @@ ...@@ -122,6 +124,16 @@
login:'user/login', login:'user/login',
logout:'user/logout' logout:'user/logout'
}), }),
toPrivacy(){
uni.navigateTo({
url:'/pages/agree-list/privacy/privacy'
})
},
toService(){
uni.navigateTo({
url:'/pages/agree-list/service/service'
})
},
initProvider() { initProvider() {
const filters = ['weixin', 'qq', 'sinaweibo', 'univerify']; const filters = ['weixin', 'qq', 'sinaweibo', 'univerify'];
uni.getProvider({ uni.getProvider({
......
<template>
<view class="content">
<uni-list class="content">
<uni-list-item v-for="(item , index) in agreeList" :key="index" :title="item.title" :to="item.to" :clickable="true" @click="itemClick(item)" :showSwitch="item.showSwitch" :switchChecked="item.isChecked"></uni-list-item>
</uni-list>
<button class="bottom-back" @click="clickLogout"><text class="bottom-back-text">退出登录</text></button>
</view>
</template>
<script>
import { isOn, setting } from '@/common/dc-push/push.js';
import { mapMutations } from 'vuex';
export default {
data() {
return {
agreeList:[
{
title:'个人资料',
to:''
},
{
title:'修改密码',
to:''
},{
title:'注销用户',
event:''
},{
title:'推送功能',
name:'push',
event:'openSetting',
isChecked:false,
showSwitch:true
},{
title:'清理缓存',
event:''
}
]
}
},
onShow() {
let pushIsOn = isOn();
this.agreeList.forEach(item=>{
item.name == 'push' ? (item.isChecked = pushIsOn) : '';
})
},
methods:{
...mapMutations({
logout:'user/logout'
}),
clickLogout(){
this.logout();
uni.navigateBack();
},
itemClick(item){
if(!item.to && item.event){
this[item.event]();
}
},
/**
* 打开设置页面
*/
openSetting(){
setting();
}
}
}
</script>
<style>
.content{
width: 750rpx;
display: flex;
flex-direction: column;
/* align-items: center; */
flex: 1;
}
.bottom-back{
width: 750rpx;
height: 120rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border: none;
border-width: 0;
border-radius: 0;
}
.bottom-back-text{
font-size: 40rpx;
color: #DD524D;
}
</style>
<template>
<view class="content">
<uni-list>
<uni-list-item>
<template v-slot:body>
<view class="avatar-box">
<image class="avatar-img" :src="userInfo.avatar || '/static/logo.png'" @click="chooseImg" mode="aspectFill"></image>
</view>
</template>
</uni-list-item>
</uni-list>
</view>
</template>
<script>
import {
mapGetters,
mapMutations
} from 'vuex';
const db = uniCloud.database();
export default {
data() {
return {
}
},
computed: {
...mapGetters({
userInfo: 'user/info'
})
},
onLoad() {
console.log(this.userInfo);
},
methods: {
...mapMutations({
login:'user/login'
}),
// 选择图片
chooseImg(){
uni.chooseImage({
count:1,
success:(res)=> {
uni.$on('uploadAvatarAfter', ({url})=>{
console.log(url);
this.uploadUserInfo({avatar:url});
})
uni.navigateTo({
url:'./uploadCutImageToUnicloud?path=' + res.tempFilePaths[0],
});
}
})
},
/**
* @param {Object} data 更新用户信息
* key 需要更新的用户字段
* value 更新后的用户字段值
*/
uploadUserInfo(data){
db.collection('uni-id-users').where({
_id: this.userInfo._id
})
.update(data)
.then(res=>{
console.log(res);
})
.catch(err=>{
console.log(err);
})
}
}
}
</script>
<style>
.content{
width: 750rpx;
display: flex;
flex-direction: column;
/* align-items: center; */
flex: 1;
}
.avatar-box{
width: 700rpx;
height: 200rpx;
display: flex;
justify-content: center;
align-items: center;
}
.avatar-img{
width: 150rpx;
height: 150rpx;
border-radius: 75rpx;
border-width: 1rpx;
border-color: #999999;
}
</style>
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 30 30" style="enable-background:new 0 0 30 30;" xml:space="preserve">
<style type="text/css">
.st0{fill:#606060;}
.st1{fill:none;stroke:#FFFFFF;stroke-width:2.4306;stroke-miterlimit:10;}
.st2{fill:#FFFFFF;}
</style>
<g>
<path class="st2" d="M11.6,11c0.4,0.4,0.6,0.9,0.6,1.5c0,0.6-0.2,1.1-0.6,1.4c-0.4,0.4-0.9,0.6-1.5,0.6c-0.6,0-1.1-0.2-1.5-0.6
c-0.4-0.4-0.6-0.9-0.6-1.4s0.2-1.1,0.6-1.5c0.4-0.4,0.9-0.6,1.5-0.6C10.8,10.4,11.2,10.6,11.6,11z M24.6,18.4V6.7H5.4v12l1.8-1.8
c0.3-0.3,0.6-0.4,1-0.4c0.4,0,0.7,0.1,1,0.4l1.8,1.8l5.8-7c0.3-0.3,0.6-0.5,1.1-0.5c0.4,0,0.8,0.2,1.1,0.5
C18.8,11.6,24.6,18.4,24.6,18.4z M25.6,5.7C25.9,6,26,6.3,26,6.7v16.1c0,0.4-0.1,0.7-0.4,1c-0.3,0.3-0.6,0.4-1,0.4H5.4
c-0.4,0-0.7-0.1-1-0.4c-0.3-0.3-0.4-0.6-0.4-1V6.7c0-0.4,0.1-0.7,0.4-1c0.3-0.3,0.6-0.4,1-0.4h19.3C25,5.3,25.3,5.4,25.6,5.7z"/>
<path class="st1" d="M24.3,21.5H5.7c-0.2,0-0.3-0.2-0.3-0.3V7c0-0.2,0.2-0.3,0.3-0.3h18.6c0.2,0,0.3,0.2,0.3,0.3v14.2
C24.6,21.3,24.5,21.5,24.3,21.5z"/>
</g>
</svg>
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="30px" height="30px" viewBox="0 0 30 30" style="enable-background:new 0 0 30 30;" xml:space="preserve">
<style type="text/css">
.st0{fill:none;stroke:#FFFFFF;stroke-width:2.4306;stroke-miterlimit:10;}
.st1{fill:#FFFFFF;}
</style>
<g>
<path class="st0" d="M17.1,24.2h-12c-0.2,0-0.3-0.2-0.3-0.3v-9.3c0-0.2,0.2-0.3,0.3-0.3h12c0.2,0,0.3,0.2,0.3,0.3v9.3
C17.5,24.1,17.3,24.2,17.1,24.2z"/>
<path class="st0" d="M16.6,5.4c4.8,0,8.7,3.9,8.7,8.7"/>
<polyline class="st0" points="19.3,10.1 14.9,5.6 19.3,1.2 "/>
</g>
</svg>
$edge-border-width = 6rpx
.flex-auto
flex auto
.bg-transparent
background-color rgba(0, 0, 0, 0.9)
transition-duration 0.35s
.l-clipper
width 100vw
height calc( 100vh - var(--window-top))
background-color rgba(0, 0, 0, 0.9)
position fixed
top var(--window-top)
left 0
z-index 1
&-mask
position relative
z-index 2
pointer-events: none
&__content
pointer-events: none;
position absolute
border 1rpx solid rgba(255,255,255,.3)
box-sizing border-box
box-shadow: rgba(0, 0, 0, 0.5) 0 0 0 80vh;
background: transparent;
&::before,&::after
content ''
position absolute
border 1rpx dashed rgba(255,255,255,.3)
&::before
width 100%
top 33.33%
height 33.33%
border-left none
border-right none
&::after
width 33.33%
left 33.33%
height 100%
border-top none
border-bottom none
&__edge
position absolute
// left 6rpx
width 34rpx
height 34rpx
border $edge-border-width solid #ffffff
pointer-events auto
&::before
content ''
position absolute
width 40rpx
height 40rpx
background-color transparent
&:nth-child(1)
left: - $edge-border-width
top: - $edge-border-width
border-bottom-width 0 !important
border-right-width 0 !important
&:before
top -50%
left -50%
&:nth-child(2)
right: - $edge-border-width
top: - $edge-border-width
border-bottom-width 0 !important
border-left-width 0 !important
&:before
top -50%
left 50%
&:nth-child(3)
left: - $edge-border-width
bottom: - $edge-border-width
border-top-width 0 !important
border-right-width 0 !important
&:before
bottom -50%
left -50%
&:nth-child(4)
right: - $edge-border-width
bottom: - $edge-border-width
border-top-width 0 !important
border-left-width 0 !important
&:before
bottom -50%
left 50%
&-image
width 100%
border-style none
position absolute
top 0
left 0
z-index 1
-webkit-backface-visibility hidden
backface-visibility hidden
transform-origin center
&-canvas
position fixed
z-index 10
left -200vw
top -200vw
pointer-events none
&-tools
position fixed
left 0
bottom 10px
width 100%
z-index 99
color #fff
&__btns
font-weight bold
display flex
align-items center
justify-content space-between
width 100%
padding 20rpx 40rpx
box-sizing border-box
.cancel
width 112rpx
height 60rpx
text-align center
line-height 60rpx
.confirm
width 112rpx
height 60rpx
line-height 60rpx
background-color #07c160
border-radius 6rpx
text-align center
image
display block
width 60rpx
height 60rpx
<template>
<view class="l-clipper" disable-scroll :style="'z-index: ' + zIndex">
<view
class="l-clipper-mask"
@touchstart.stop.prevent="clipTouchStart"
@touchmove.stop.prevent="clipTouchMove"
@touchend.stop.prevent="clipTouchEnd">
<view class="l-clipper__content" :style="clipStyle">
<view class="l-clipper__edge" v-for="(item, index) in [0,0,0,0]" :key="index"></view>
</view>
</view>
<image
class="l-clipper-image"
@error="imageLoad"
@load="imageLoad"
@touchstart="imageTouchStart"
@touchmove="imageTouchMove"
@touchend="imageTouchEnd"
:src="image"
mode="widthFix"
v-if="image"
:style="imageStyle"/>
<canvas
canvas-id="l-clipper"
id="l-clipper"
disable-scroll
:style="'width: ' + (canvasWidth * scaleRatio) + 'px; height:' + (canvasHeight * scaleRatio) + 'px;'"
class="l-clipper-canvas"
></canvas>
<view class="l-clipper-tools">
<view class="l-clipper-tools__btns">
<view v-if="isShowCancelBtn" @click="cancel">
<slot name="cancel" v-if="$slots.cancel" />
<view v-else class="cancel" >取消</view>
</view>
<view v-if="isShowPhotoBtn" @click="uploadImage">
<slot name="photo" v-if="$slots.photo" />
<image v-else :src="require('./images/photo.svg')" />
</view>
<view v-if="isShowRotateBtn" @click="rotate">
<slot name="rotate" v-if="$slots.rotate" />
<image v-else :src="require('./images/rotate.svg')" data-type="inverse" />
</view>
<view v-if="isShowConfirmBtn" @click="confirm">
<slot name="confirm" v-if="$slots.confirm" />
<view v-else class="confirm" >确定</view>
</view>
</view>
<slot></slot>
</view>
</view>
</template>
<script>
import { pathToBase64, determineDirection, calcImageOffset, calcImageScale, calcImageSize, calcPythagoreanTheorem, clipTouchMoveOfCalculate, imageTouchMoveOfCalcOffset } from './utils';
export default {
// version: '0.1.0',
name: 'l-clipper',
props: {
zIndex: {
type: Number,
default: 99
},
imageUrl: {
type: String
},
quality: {
type: Number,
default: 1
},
width: {
type: Number,
default: 400
},
height: {
type: Number,
default: 400
},
minWidth: {
type: Number,
default: 200
},
maxWidth: {
type: Number,
default: 600
},
minHeight: {
type: Number,
default: 200
},
maxHeight: {
type: Number,
default: 600
},
isLockWidth: {
type: Boolean,
default: false
},
isLockHeight: {
type: Boolean,
default: false
},
isLockRatio: {
type: Boolean,
default: true
},
scaleRatio: {
type: Number,
default: 1
},
minRatio: {
type: Number,
default: 0.5
},
maxRatio: {
type: Number,
default: 2
},
isDisableScale: {
type: Boolean,
default: false
},
isDisableRotate: {
type: Boolean,
default: false
},
isLimitMove: {
type: Boolean,
default: false
},
isShowPhotoBtn: {
type: Boolean,
default: true
},
isShowRotateBtn: {
type: Boolean,
default: true
},
isShowConfirmBtn: {
type: Boolean,
default: true
},
isShowCancelBtn: {
type: Boolean,
default: true
},
rotateAngle: {
type: Number,
default: 90
}
},
data() {
return {
canvasWidth: 0,
canvasHeight: 0,
cutX: 0,
cutY: 0,
aWidth: this.width,
aHeight: this.height,
clipWidth: 0,
clipHeight: 0,
cutAnimation: false,
imageWidth: 0,
imageHeight: 0,
imageTop: 0,
imageLeft: 0,
scale: 1,
angle: 0,
image: this.imageUrl,
sysinfo: {},
moveThrottleTimer: null,
moveThrottleFlag: true,
timeCutcenter: null,
flagCutTouch: false,
flagEndTouch: false,
cutstart: {},
cutAnimationTime: null,
touchRelative: [{x: 0,y: 0}],
hypotenuseLength: 0,
ctx: null
};
},
computed: {
clipStyle() {
const {clipWidth, clipHeight, cutY, cutX, cutAnimation} = this
return `
width: ${clipWidth}px;
height:${clipHeight}px;
transition-property: ${cutAnimation ? '' : 'background'};
left: ${cutX}px;
top: ${cutY}px
`
},
imageStyle() {
const {imageWidth, imageHeight, imageLeft, imageTop, cutAnimation, scale, angle} = this
return `
width:${imageWidth ? imageWidth + 'px' : 'auto'}; height: ${imageHeight ? imageHeight + 'px' : 'auto'};
transform: translate3d(${imageLeft - imageWidth / 2}px, ${imageTop - imageHeight / 2}px, 0) scale(${scale}) rotate(${angle}deg);
transition-duration: ${cutAnimation ? 0.35 : 0}s
`
},
clipSize() {
const { clipWidth, clipHeight } = this;
return { clipWidth, clipHeight };
},
cutPoint() {
const { cutY, cutX } = this;
return { cutY, cutX };
}
},
watch: {
// #ifdef H5
imageUrl: {
handler: async function(url) {
const res = await pathToBase64(url)
if(res) {
this.image = res
}
},
immediate: true,
},
// #endif
image:{
handler: function (url) {
this.getImageInfo(url)
},
immediate: true,
},
clipSize({ widthVal, heightVal }) {
let { minWidth, minHeight } = this;
minWidth = minWidth / 2;
minHeight = minHeight / 2;
if (widthVal < minWidth) {
this.clipWidth = minWidth;
}
if (heightVal < minHeight) {
this.clipHeight = minHeight;
}
this.computeCutSize();
},
angle(val) {
this.cutAnimation = true;
this.moveStop();
const { isLimitMove } = this;
if (isLimitMove && val % 90) {
this.angle = Math.round(val / 90) * 90;
}
this.imgMarginDetectionScale();
},
cutAnimation(val) {
clearTimeout(this.cutAnimationTime);
if (val) {
let cutAnimationTime = setTimeout(() => {
this.cutAnimation = false;
}, 260);
this.cutAnimationTime = cutAnimationTime;
}
},
isLimitMove(val) {
if (val) {
if (this.angle % 90) {
this.angle = Math.round(this.angle / 90) * 90;
}
this.imgMarginDetectionScale();
}
},
cutPoint() {
this.cutDetectionPosition();
},
aWidth(width, oWidth) {
if (width !== oWidth) {
this.clipWidth = width / 2
}
},
aHeight(height, oHeight) {
if (height !== oHeight) {
this.clipHeight = height / 2
}
}
},
mounted() {
const sysinfo = uni.getSystemInfoSync();
this.sysinfo = sysinfo;
this.setCutInfo();
this.setCutCenter();
this.computeCutSize();
this.cutDetectionPosition();
},
methods: {
getImageInfo(url) {
if (!url) return;
uni.showLoading({
title: '请稍候...',
mask: true
});
uni.getImageInfo({
src: url,
success: res => {
this.imgComputeSize(res.width, res.height);
if (this.isLimitMove) {
this.imgMarginDetectionScale();
this.$emit('ready', res);
}
},
fail: () => {
this.imgComputeSize();
if (this.isLimitMove) {
this.imgMarginDetectionScale();
}
}
});
},
setCutInfo() {
const { aWidth, aHeight, sysinfo } = this;
const clipWidth = aWidth / 2;
const clipHeight = aHeight / 2;
const cutY = (sysinfo.windowHeight - clipHeight) / 2;
const cutX = (sysinfo.windowWidth - clipWidth) / 2;
const imageLeft = sysinfo.windowWidth / 2;
const imageTop = sysinfo.windowHeight / 2;
this.ctx = uni.createCanvasContext('l-clipper', this);
this.clipWidth = clipWidth;
this.clipHeight = clipHeight;
this.cutX = cutX;
this.cutY = cutY;
this.canvasHeight = clipHeight;
this.canvasWidth = clipWidth;
this.imageLeft = imageLeft;
this.imageTop = imageTop;
},
setCutCenter() {
const { sysInfo, clipHeight, clipWidth, imageTop, imageLeft } = this;
let sys = sysInfo || uni.getSystemInfoSync();
let cutY = (sys.windowHeight - clipHeight) * 0.5;
let cutX = (sys.windowWidth - clipWidth) * 0.5;
this.imageTop = imageTop - this.cutY + cutY;
this.imageLeft = imageLeft - this.cutX + cutX;
this.cutY = cutY;
this.cutX = cutX;
},
computeCutSize() {
const { clipHeight, clipWidth, sysinfo, cutX, cutY } = this;
if (clipWidth > sysinfo.windowWidth) {
this.clipWidth = sysinfo.windowWidth;
} else if (clipWidth + cutX > sysinfo.windowWidth) {
this.cutX = sysinfo.windowWidth - cutX;
}
if (clipHeight > sysinfo.windowHeight) {
this.clipHeight = sysinfo.windowHeight;
} else if (clipHeight + cutY > sysinfo.windowHeight) {
this.cutY = sysinfo.windowHeight - cutY;
}
},
cutDetectionPosition() {
const { cutX, cutY, sysinfo, clipHeight, clipWidth } = this;
let cutDetectionPositionTop = () => {
if (cutY < 0) {
this.cutY = 0;
}
if (cutY > sysinfo.windowHeight - clipHeight) {
this.cutY = sysinfo.windowHeight - clipHeight;
}
},
cutDetectionPositionLeft = () => {
if (cutX < 0) {
this.cutX = 0;
}
if (cutX > sysinfo.windowWidth - clipWidth) {
this.cutX = sysinfo.windowWidth - clipWidth;
}
};
if (cutY === null && cutX === null) {
let newCutY = (sysinfo.windowHeight - clipHeight) * 0.5;
let newCutX = (sysinfo.windowWidth - clipWidth) * 0.5;
this.cutX = newCutX;
this.cutY = newCutY;
} else if (cutY !== null && cutX !== null) {
cutDetectionPositionTop();
cutDetectionPositionLeft();
} else if (cutY !== null && cutX === null) {
cutDetectionPositionTop();
this.cutX = (sysinfo.windowWidth - clipWidth) / 2;
} else if (cutY === null && cutX !== null) {
cutDetectionPositionLeft();
this.cutY = (sysinfo.windowHeight - clipHeight) / 2;
}
},
imgComputeSize(width, height) {
const { imageWidth, imageHeight } = calcImageSize(width, height, this);
this.imageWidth = imageWidth;
this.imageHeight = imageHeight;
},
imgMarginDetectionScale(scale) {
if (!this.isLimitMove) return;
const currentScale = calcImageScale(this, scale);
this.imgMarginDetectionPosition(currentScale);
},
imgMarginDetectionPosition(scale) {
if (!this.isLimitMove) return;
const { scale: currentScale, left, top } = calcImageOffset(this, scale);
this.imageLeft = left;
this.imageTop = top;
this.scale = currentScale;
},
moveThrottle() {
if( this.moveThrottleFlag !== true) {
this.moveThrottleFlag = true
}
},
moveDuring() {
clearTimeout(this.timeCutcenter);
},
moveStop() {
clearTimeout(this.timeCutcenter);
const timeCutcenter = setTimeout(() => {
if (!this.cutAnimation) {
this.cutAnimation = true;
}
this.setCutCenter();
}, 800);
this.timeCutcenter = timeCutcenter;
},
clipTouchStart(event) {
// #ifdef H5
event.preventDefault()
// #endif
if (!this.image) {
uni.showToast({
title: '请选择图片',
icon: 'none'
});
return;
}
const currentX = event.touches[0].clientX;
const currentY = event.touches[0].clientY;
const { cutX, cutY, clipWidth, clipHeight } = this;
const corner = determineDirection(cutX, cutY, clipWidth, clipHeight, currentX, currentY);
this.moveDuring();
if(!corner) {
return
}
this.cutstart = {
width: clipWidth,
height: clipHeight,
x: currentX,
y: currentY,
cutY,
cutX,
corner
};
this.flagCutTouch = true;
this.flagEndTouch = true;
},
clipTouchMove(event) {
// #ifdef H5
event.stopPropagation()
event.preventDefault()
// #endif
if (!this.image) {
uni.showToast({
title: '请选择图片',
icon: 'none'
});
return;
}
const { flagCutTouch, moveThrottleFlag } = this;
if (flagCutTouch && moveThrottleFlag) {
const { isLockRatio, isLockHeight, isLockWidth } = this;
if (isLockRatio && (isLockWidth || isLockHeight)) return;
this.moveThrottleFlag = false;
if(this.moveThrottleFlag !== false) {
this.moveThrottleFlag = false;
}
this.moveThrottle();
const { width, height, cutX, cutY } = clipTouchMoveOfCalculate(this, event);
if (!isLockWidth && !isLockHeight) {
this.clipWidth = width;
this.clipHeight = height;
this.cutX = cutX;
this.cutY = cutY;
} else if (!isLockWidth) {
this.clipWidth = width// clipWidth;
this.cutX = cutX;
} else if (!isLockHeight) {
this.clipHeight = height//clipHeight;
this.cutY = cutY;
}
this.imgMarginDetectionScale();
}
},
clipTouchEnd() {
this.moveStop();
this.flagCutTouch = false;
},
imageTouchStart(e) {
// #ifdef H5
event.preventDefault()
// #endif
this.flagEndTouch = false;
this.cutAnimation = false;
const { imageLeft, imageTop } = this;
const clientXForLeft = Math.round(e.touches[0].clientX);
const clientYForLeft = Math.round(e.touches[0].clientY);
let touchRelative = [];
if (e.touches.length === 1) {
touchRelative[0] = {
x: clientXForLeft - imageLeft,
y: clientYForLeft - imageTop
};
this.touchRelative = touchRelative;
} else {
const clientXForRight = Math.round(e.touches[1].clientX);
const clientYForRight = Math.round(e.touches[1].clientY);
let width = Math.abs(clientXForLeft - clientXForRight);
let height = Math.abs(clientYForLeft - clientYForRight);
const hypotenuseLength = calcPythagoreanTheorem(width, height);
touchRelative = [
{
x: clientXForLeft - imageLeft,
y: clientYForLeft - imageTop
},
{
x: clientXForRight - imageLeft,
y: clientYForRight - imageTop
}
];
this.touchRelative = touchRelative;
this.hypotenuseLength = hypotenuseLength;
}
},
imageTouchMove(e) {
// #ifdef H5
event.preventDefault()
// #endif
const { flagEndTouch, moveThrottleFlag } = this;
if (flagEndTouch || !moveThrottleFlag) return;
const clientXForLeft = Math.round(e.touches[0].clientX);
const clientYForLeft = Math.round(e.touches[0].clientY);
this.moveThrottleFlag = false;
this.moveThrottle();
this.moveDuring();
if (e.touches.length === 1) {
const { left, top } = imageTouchMoveOfCalcOffset(this, clientXForLeft, clientYForLeft);
this.imageLeft = left;
this.imageTop = top;
this.imgMarginDetectionPosition();
} else {
const clientXForRight = Math.round(e.touches[1].clientX);
const clientYForRight = Math.round(e.touches[1].clientY);
let width = Math.abs(clientXForLeft - clientXForRight),
height = Math.abs(clientYForLeft - clientYForRight),
hypotenuse = calcPythagoreanTheorem(width, height),
scale = this.scale * (hypotenuse / this.hypotenuseLength);
if (this.isDisableScale) {
scale = 1;
} else {
scale = scale <= this.minRatio ? this.minRatio : scale;
scale = scale >= this.maxRatio ? this.maxRatio : scale;
this.$emit('change', {
width: this.imageWidth * scale,
height: this.imageHeight * scale
});
}
this.imgMarginDetectionScale(scale);
this.hypotenuseLength = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
this.scale = scale;
}
},
imageTouchEnd() {
this.flagEndTouch = true;
this.moveStop();
},
uploadImage() {
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: res => {
const tempFilePaths = res.tempFilePaths;
this.image = tempFilePaths[0];
}
});
},
imageReset() {
const sys = this.sysinfo || uni.getSystemInfoSync();
this.scale = 1;
this.angle = 0;
this.imageTop = sys.windowHeight / 2;
this.imageLeft = sys.windowWidth / 2;
},
imageLoad(e) {
this.imageReset();
uni.hideLoading();
this.$emit('ready', e.detail);
},
rotate(event) {
if (this.isDisableRotate) return;
if (!this.image) {
uni.showToast({
title: '请选择图片',
icon: 'none'
});
return;
}
const { rotateAngle } = this;
const originAngle = this.angle
const type = event.currentTarget.dataset.type;
if (type === 'along') {
this.angle = originAngle + rotateAngle
} else {
this.angle = originAngle - rotateAngle
}
this.$emit('rotate', this.angle);
},
confirm() {
if (!this.image) {
uni.showToast({
title: '请选择图片',
icon: 'none'
});
return;
}
uni.showLoading({
title: '加载中'
});
const { clipHeight, clipWidth, ctx, scale, imageLeft, imageTop, cutX, cutY, angle, scaleRatio, image, quality, type: imageType } = this;
let { canvasHeight, canvasWidth } = this;
const draw = () => {
const imageWidth = this.imageWidth * scale * scaleRatio;
const imageHeight = this.imageHeight * scale * scaleRatio;
const xpos = imageLeft - cutX;
const ypos = imageTop - cutY;
ctx.translate(xpos * scaleRatio, ypos * scaleRatio);
ctx.rotate((angle * Math.PI) / 180);
ctx.drawImage(image, -imageWidth / 2, -imageHeight / 2, imageWidth, imageHeight);
ctx.draw(false, () => {
const width = clipWidth * scaleRatio
const height = clipHeight * scaleRatio
let params = {
x: 0,
y: 0,
width,
height,
destWidth: width,
destHeight: height,
canvasId: 'l-clipper',
fileType: 'png',
quality,
success: (res) => {
data.url = res.tempFilePath;
uni.hideLoading();
this.$emit('success', data);
},
fail: (error) => {
console.error('error', error)
this.$emit('fail', error);
}
};
let data = {
url: '',
width,
height
};
uni.canvasToTempFilePath(params, this)
});
};
if (canvasWidth !== clipWidth || canvasHeight !== clipHeight) {
canvasWidth = clipWidth;
canvasHeight = clipHeight;
ctx.draw();
setTimeout(() => {
draw();
}, 100);
} else {
draw();
}
},
cancel() {
this.$emit('cancel', false)
},
}
};
</script>
<style lang="stylus" scoped>
@import './index'
</style>
/**
* h5网络地址转base64
*/
export function pathToBase64(path) {
// #ifdef H5
return new Promise((resolve, reject) => {
const _fileReader = (blob) => {
const fileReader = new FileReader();
fileReader.onload = (e) => {
resolve(e.target.result);
};
fileReader.readAsDataURL(blob);
fileReader.onerror = (error) => {
console.error('blobToBase64 error:', JSON.stringify(error))
reject(new Error('blobToBase64 error'));
};
}
if (/^(http|\/\/)/.test(path) && typeof FileReader === 'function') {
window.URL = window.URL || window.webkitURL;
const xhr = new XMLHttpRequest();
xhr.open("get", path, true);
xhr.timeout = 2000;
xhr.responseType = "blob";
xhr.onload = function() {
if (this.status == 200) {
_fileReader(this.response)
}
}
xhr.send();
}
})
// #endif
}
/**
* 判断手指触摸位置
*/
export function determineDirection(cutX, cutY, clipWidth, clipHeight, currentX, currentY) {
const EXPAND_SIZE = 24;
let leftx1 = cutX - EXPAND_SIZE;
let leftx2 = cutX + EXPAND_SIZE;
let topy1 = cutY - EXPAND_SIZE;
let topy2 = cutY + EXPAND_SIZE;
let rightx1 = cutX + clipWidth - EXPAND_SIZE;
let rightx2 = cutX + clipWidth + EXPAND_SIZE;
let bottomy1 = cutY + clipHeight - EXPAND_SIZE;
let bottomy2 = cutY + clipHeight + EXPAND_SIZE;
let corner;
const isRight = currentX > rightx1 && currentX < rightx2;
const isLeft = currentX > leftx1 && currentX < leftx2;
const isBottom = currentY > bottomy1 && currentY < bottomy2;
const isTop = currentY > topy1 && currentY < topy2;
if (isRight && isBottom) {
corner = 1;
} else if (isRight && isTop) {
corner = 2;
} else if (isLeft && isTop) {
corner = 3;
} else if (isLeft && isBottom) {
corner = 4;
}
return corner;
}
/**
* 图片边缘检测检测时,计算图片偏移量
*/
export function calcImageOffset(data, scale) {
let {
imageLeft: left,
imageTop: top,
imageWidth,
imageHeight,
cutX,
clipWidth,
cutY,
clipHeight
} = data
scale = scale || data.scale;
if ((data.angle / 90) % 2) {
imageWidth = mageHeight;
imageHeight = mageWidth;
}
// 当前图片宽度/高度
const currentImageSize = (size) => (size * scale) / 2;
const currentImageWidth = currentImageSize(imageWidth);
const currentImageHeight = currentImageSize(imageHeight);
left = cutX + currentImageWidth >= left ? left : cutX + currentImageWidth;
left = cutX + clipWidth - currentImageWidth <= left ? left : cutX + clipWidth - currentImageWidth;
top = cutY + currentImageHeight >= top ? top : cutY + currentImageHeight;
top = cutY + clipHeight - currentImageHeight <= top ? top : cutY + clipHeight - currentImageHeight;
return {
left,
top,
scale
};
}
/**
* 图片边缘检测时,计算图片缩放比例
*/
export function calcImageScale(data, scale) {
scale = scale || data.scale;
let {
imageWidth,
imageHeight,
clipWidth,
clipHeight,
angle
} = data
if ((angle / 90) % 2) {
imageWidth = imageHeight;
imageHeight = imageWidth;
}
if (imageWidth * scale < clipWidth) {
scale = clipWidth / imageWidth;
}
if (imageHeight * scale < clipHeight) {
scale = Math.max(scale, clipHeight / imageHeight);
}
return scale;
}
/**
* 计算图片尺寸
*/
export function calcImageSize(width, height, data) {
let imageWidth = width,
imageHeight = height;
let {
clipWidth,
clipHeight,
sysinfo,
width: oWidth,
height: oHeight
} = data
if (imageWidth && imageHeight) {
if (imageWidth / imageHeight > (clipWidth || oWidth) / (clipWidth || oHeight)) {
imageHeight = clipHeight || oHeight;
imageWidth = (width / height) * imageHeight;
} else {
imageWidth = clipWidth || oWidth;
imageHeight = (height / width) * imageWidth;
}
} else {
let sys = sysinfo || uni.getSystemInfoSync();
imageWidth = sys.windowWidth;
imageHeight = 0;
}
return {
imageWidth,
imageHeight
};
}
/**
* 勾股定理求斜边
*/
export function calcPythagoreanTheorem(width, height) {
return Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
}
/**
* 拖动裁剪框时计算
*/
export function clipTouchMoveOfCalculate(data, event) {
const clientX = event.touches[0].clientX;
const clientY = event.touches[0].clientY;
const {
clipWidth,
clipHeight,
cutY: oldCutY,
cutX: oldCutX,
cutstart,
isLockRatio
} = data;
let {
maxWidth,
minWidth,
maxHeight,
minHeight
} = data;
maxWidth = maxWidth / 2;
minWidth = minWidth / 2;
minHeight = minHeight / 2;
maxHeight = maxHeight / 2;
let width = clipWidth,
height = clipHeight,
cutY = oldCutY,
cutX = oldCutX,
sizecorrect = () => {
width = width <= maxWidth ? (width >= minWidth ? width : minWidth) : maxWidth;
height = height <= maxHeight ? (height >= minHeight ? height : minHeight) : maxHeight;
},
sizeinspect = () => {
sizecorrect();
if ((width > maxWidth || width < minWidth || height > maxHeight || height < minHeight) && isLockRatio) {
return false;
} else {
return true;
}
};
if (cutstart.corner) {
height = cutstart.height + (cutstart.corner > 1 && cutstart.corner < 4 ? 1 : -1) * (cutstart.y - clientY);
}
switch (cutstart.corner) {
case 1:
width = cutstart.width - cutstart.x + clientX;
if (isLockRatio) {
height = width / (clipWidth / clipHeight);
}
if (!sizeinspect()) return;
break;
case 2:
width = cutstart.width - cutstart.x + clientX;
if (isLockRatio) {
height = width / (clipWidth / clipHeight);
}
if (!sizeinspect()) {
return;
} else {
cutY = cutstart.cutY - (height - cutstart.height);
}
break;
case 3:
width = cutstart.width + cutstart.x - clientX;
if (isLockRatio) {
height = width / (clipWidth / clipHeight);
}
if (!sizeinspect()) {
return;
} else {
cutY = cutstart.cutY - (height - cutstart.height);
cutX = cutstart.cutX - (width - cutstart.width);
}
break;
case 4:
width = cutstart.width + cutstart.x - clientX;
if (isLockRatio) {
height = width / (clipWidth / clipHeight);
}
if (!sizeinspect()) {
return;
} else {
cutX = cutstart.cutX - (width - cutstart.width);
}
break;
default:
break;
}
return {
width,
height,
cutX,
cutY
};
}
/**
* 单指拖动图片计算偏移
*/
export function imageTouchMoveOfCalcOffset(data, clientXForLeft, clientYForLeft) {
let left = clientXForLeft - data.touchRelative[0].x,
top = clientYForLeft - data.touchRelative[0].y;
return {
left,
top
};
}
export default (callback,options)=>{
options = options||{"width":600,"height":600};
uni.chooseImage({
sizeType:['original'],
count:1,
...options,
complete:({tempFiles:[{path}]})=> {
uni.navigateTo({
url:'/common/uploadCutImageToUnicloud/uploadCutImageToUnicloud?path='+path+"&options="+JSON.stringify(options),
animationType:'fade-in',
events:{
url(url){
callback(url)
}
}
})
}
})
}
\ No newline at end of file
<template>
<view class="content" >
<limeClipper :width="options.width" :scale-ratio="2" :height="options.height" :image-url="path"
@success="successFn" @cancel="cancel" />
</view>
</template>
<script>
import limeClipper from './limeClipper/limeClipper.vue';
export default {
components: {limeClipper},
data() {return {path: '',options:{"width":600,"height":600}}},
onLoad({path,options}) {
this.path = path
if(options){
this.options = JSON.parse(options)
}
},
methods:{
successFn(e){
uni.getImageInfo({
src:e.url,
complete: (e) => {
console.log(e);
}
})
this.uploadImgToUnicloud(e.url,(url)=>{
//console.log(url);
uni.$emit('uploadAvatarAfter', {url});
uni.navigateBack()
})
},
uploadImgToUnicloud(url,callback){
uni.showLoading()
uniCloud.uploadFile({
cloudPath:Math.ceil((Math.random()+Math.random()+Math.random()+1)*1000000)+Date.now()+".png",
filePath:url
})
.then(res=>{
//console.log(res);
callback(res.fileID)
uni.hideLoading()
})
},
cancel(){
uni.navigateBack()
}
}
}
</script>
<style>
.box{
width: 400rpx;
}
.mt{
margin-top: -10px;
}
</style>
\ No newline at end of file
<template> <template>
<view class="center"> <view class="center">
<view class="logo" @click="goLogin" :hover-class="!login ? 'logo-hover' : ''"> <view class="logo" @click="goLogin" :hover-class="!login ? 'logo-hover' : ''">
<image class="logo-img" :src="login ? (userInfo.avatarUrl || avatarUrl) :avatarUrl"></image> <image class="logo-img" :src="login ? (userInfo.avatar || avatarUrl) :avatarUrl"></image>
<view class="logo-title"> <view class="logo-title">
<text class="uer-name">Hi,{{login ? userInfo.username : '您未登录'}}</text> <text class="uer-name">Hi,{{login ? userInfo.username : '您未登录'}}</text>
<text class="go-login-navigat-arrow navigat-arrow" v-if="!login">&#xe65e;</text> <text class="go-login-navigat-arrow navigat-arrow" v-if="!login">&#xe65e;</text>
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
</view> </view>
<uni-list class="center-list"> <uni-list class="center-list">
<template v-for="(sublist , index) in ucenterList"> <template v-for="(sublist , index) in ucenterList">
<uni-list-item :title="item.title" :rightText="item.rightText" :link="item.link" <uni-list-item :title="item.title" :rightText="item.rightText" :to="item.to"
v-for="(item, subIndex) in sublist" :key="(index + '_' + subIndex)"></uni-list-item> v-for="(item, subIndex) in sublist" :key="(index + '_' + subIndex)" @click="ucenterListClick(item)" :clickable="true"></uni-list-item>
<!-- #ifdef APP-NVUE --> <!-- #ifdef APP-NVUE -->
<cell class="center-list-cell"></cell> <cell class="center-list-cell"></cell>
<!-- #endif --> <!-- #endif -->
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
mapGetters, mapGetters,
mapMutations mapMutations
} from 'vuex'; } from 'vuex';
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
export default { export default {
data() { data() {
return { return {
...@@ -38,24 +39,27 @@ ...@@ -38,24 +39,27 @@
title: '我的积分' title: '我的积分'
}], }],
[{ [{
title: '政策与协议' title: '政策与协议',
to:'/pages/agree-list/agree-list'
}, { }, {
title: '关于', title: '关于',
link: 'asd' to: '/pages/about/about'
}, },
//#ifdef APP-PLUS //#ifdef APP-PLUS
{ {
title: '检查更新', title: '检查更新',
rightText: `V${plus.runtime.version}_${plus.runtime.versionCode}` rightText: `V${getApp().appVersion.finall.version}_${getApp().appVersion.finall.versionCode}`,
event:'checkVersion'
} }
//#endif //#endif
], ],
[ [
{ {
title: '反馈' title: '反馈',
to:'/pages/uni-feedback/uni-feedback'
},{ },{
title: '设置', title: '设置',
link: './setting' to: '/pages/settings/settings'
} }
] ]
] ]
...@@ -68,7 +72,7 @@ ...@@ -68,7 +72,7 @@
}) })
}, },
onReady() { onReady() {
this.logout();
}, },
onShow(){ onShow(){
console.log(this.userInfo); console.log(this.userInfo);
...@@ -77,6 +81,17 @@ ...@@ -77,6 +81,17 @@
...mapMutations({ ...mapMutations({
logout:'user/logout' logout:'user/logout'
}), }),
/**
* 个人中心项目列表点击事件
*/
ucenterListClick(item){
if(!item.to && item.event){
this[item.event]();
}
},
checkVersion(){
checkUpdate();
},
goLogin() { goLogin() {
if (!this.login) { if (!this.login) {
console.log('点击前往登录'); console.log('点击前往登录');
...@@ -86,6 +101,9 @@ ...@@ -86,6 +101,9 @@
} }
else { else {
console.log('点击编辑信息'); console.log('点击编辑信息');
uni.navigateTo({
url:'./edit/edit'
})
} }
} }
} }
......
<template>
<view class="page">
<view class="feedback-title">
<text>问题和意见</text>
<text class="feedback-quick" @tap="chooseMsg">快速键入</text>
</view>
<view class="feedback-body"><textarea placeholder="请详细描述你的问题和意见..." v-model="sendDate.content"
class="feedback-textare"></textarea></view>
<view class="feedback-title"><text>图片(选填,提供问题截图,总大小10M以下)</text></view>
<view class="feedback-body feedback-uploader">
<view class="uni-uploader">
<view class="uni-uploader-head">
<view class="uni-uploader-title">点击预览图片</view>
<view class="uni-uploader-info">{{ imageList.length }}/5</view>
</view>
<view class="uni-uploader-body">
<view class="uni-uploader__files">
<block v-for="(image, index) in imageList" :key="index">
<view class="uni-uploader__file" style="position: relative;">
<image class="uni-uploader__img" :src="image" @tap="previewImage(index)"></image>
<view class="close-view" @click="close(index)">x</view>
</view>
</block>
<view class="uni-uploader__input-box" v-show="imageList.length < 5">
<view class="uni-uploader__input" @tap="chooseImg"></view>
</view>
</view>
</view>
</view>
</view>
<view class="feedback-title"><text>联系方式</text></view>
<view class="feedback-body"><input class="feedback-input" v-model="sendDate.contact"
placeholder="(选填,方便我们联系你 )" /></view>
<view class="feedback-title feedback-star-view">
<text>应用评分</text>
<view class="feedback-star-view">
<uni-rate v-model="sendDate.score" color="#bbb"></uni-rate>
</view>
</view>
<button type="default" class="feedback-submit" @tap="send">提交</button>
<view class="feedback-title"><text>用户反馈的结果可在app打包后于DCloud开发者中心查看</text></view>
</view>
</template>
<script>
const db = uniCloud.database();
const dbCmd = db.command;
export default {
data() {
return {
msgContents: ['界面显示错乱', '启动缓慢,卡出翔了', 'UI无法直视,丑哭了', '偶发性崩溃'],
stars: [1, 2, 3, 4, 5],
imageList: [],
sendDate: {
score: 0,
content: '',
contact: ''
}
};
},
onLoad() {
// #ifdef APP-PLUS
this.deviceInfo = {
appid: plus.runtime.appid,
imei: plus.device.imei, //设备标识
p: plus.os.name === 'Android' ? 'a' : 'i', //平台类型,i表示iOS平台,a表示Android平台。
md: plus.device.model, //设备型号
app_version: plus.runtime.version,
plus_version: plus.runtime.innerVersion, //基座版本号
os: plus.os.version,
net: '' + plus.networkinfo.getCurrentType()
};
//#endif
this.deviceInfo = uni.getSystemInfo();
// #ifndef APP-PLUS
//#endif
this.sendDate = Object.assign(this.deviceInfo, this.sendDate);
},
methods: {
/**
* 关闭图片
* @param {Object} e
*/
close(e) {
this.imageList.splice(e, 1);
},
/**
* 快速输入
*/
chooseMsg() {
uni.showActionSheet({
itemList: this.msgContents,
success: res => {
this.sendDate.content = this.msgContents[res.tapIndex];
}
});
},
/**
* 选择图片
*/
chooseImg() {
//选择图片
uni.chooseImage({
sourceType: ['camera', 'album'],
sizeType: 'compressed',
count: 5 - this.imageList.length,
success: res => {
this.imageList = this.imageList.concat(res.tempFilePaths);
}
});
},
/**
* 评分
* @param {Object} e
*/
chooseStar(e) {
//点击评星
this.sendDate.score = e;
},
/**
* 预览图片
* @param {Object} index
*/
previewImage(index) {
uni.previewImage({
urls: this.imageList,
current: this.imageList[index]
});
},
/**
* 提交
*/
send() {
//发送反馈
if (this.sendDate.content.length === 0) {
uni.showModal({
content: '请输入问题和意见',
showCancel: false
});
return;
}
uni.showLoading({
title: '上传中...'
});
let imgs = this.imageList.map((value, index) => {
return {
name: 'images' + index,
uri: value
};
});
// TODO 服务端限制上传文件一次最大不超过 2M, 图片一次最多不超过5张
this.request(this.sendDate, imgs)
.then(res => {
console.log(res);
if(res.success){
this.sendDate.content = '';
this.imageList = [];
return uni.showToast({
title: '反馈成功',
icon: 'none'
});
}
uni.showToast({
title: `err${res.result?.code}:${res.result?.message}`,
icon: 'none'
});
})
.catch(err => {
console.log(err);
})
.finally(()=>{
uni.hideLoading();
})
},
/**
* 发送请求到后台
*/
async request(sendDate, imgs) {
let cloud_list = [];
for (let i = 0; i < imgs.length; i++) {
let res = await uniCloud.uploadFile({
filePath: imgs[i].uri,
cloudPath: 'feedback.jpg',
onUploadProgress: function(progressEvent) {}
})
cloud_list.push(res.fileID);
}
console.log('cloud_', cloud_list);
return db.collection('opendb-feedback').add({
// ...sendDate,
"create_date": Date.now(),
"content": this.sendDate.content,
"mobile": this.sendDate.contact,
imgs: cloud_list
})
}
}
};
</script>
<style>
@import '/common/uni.css';
page {
background-color: #efeff4;
}
.input-view {
font-size: 28rpx;
}
.close-view {
text-align: center;
line-height: 14px;
height: 16px;
width: 16px;
border-radius: 50%;
background: #ff5053;
color: #ffffff;
position: absolute;
top: -6px;
right: -4px;
font-size: 12px;
}
</style>
{
"bsonType": "object",
"required": ["appid", "platform", "version", "url", "contents", "type"],
"permission": {
"read": false,
"create": false,
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "记录id,自动生成"
},
"appid": {
"bsonType": "string",
"trim": "both",
"description": "应用的AppID",
"label": "AppID",
"componentForEdit": {
"name": "uni-easyinput",
"props": {
"disabled": true
}
}
},
"name": {
"bsonType": "string",
"trim": "both",
"description": "应用名称",
"label": "应用名称",
"componentForEdit": {
"name": "uni-easyinput",
"props": {
"disabled": true
}
}
},
"title": {
"bsonType": "string",
"description": "更新标题",
"label": "更新标题"
},
"contents": {
"bsonType": "string",
"description": "更新内容",
"label": "更新内容",
"componentForEdit": {
"name": "textarea"
},
"componentForShow": {
"name": "textarea",
"props": {
"disabled": true
}
}
},
"platform": {
"bsonType": "array",
"enum": [{
"value": "Android",
"text": "安卓"
}, {
"value": "iOS",
"text": "苹果"
}],
"description": "更新平台,Android || iOS || [Android, iOS]",
"label": "平台"
},
"type": {
"bsonType": "string",
"enum": [{
"value": "native_app",
"text": "原生App安装包"
}, {
"value": "wgt",
"text": "Wgt资源包"
}],
"description": "安装包类型,native_app || wgt",
"label": "安装包类型"
},
"version": {
"bsonType": "string",
"description": "当前包版本号,必须大于当前线上发行版本号",
"label": "版本号"
},
"min_uni_version": {
"bsonType": "string",
"description": "原生App最低版本",
"label": "原生App最低版本"
},
"url": {
"bsonType": "string",
"description": "可下载安装包地址",
"label": "包地址"
},
"stable_publish": {
"bsonType": "bool",
"description": "是否上线发行",
"label": "上线发行"
},
"is_silently": {
"bsonType": "bool",
"description": "是否静默更新",
"label": "静默更新",
"defaultValue": false
},
"is_mandatory": {
"bsonType": "bool",
"description": "是否强制更新",
"label": "强制更新",
"defaultValue": false
},
"create_date": {
"bsonType": "timestamp",
"label": "上传时间",
"forceDefaultValue": {
"$env": "now"
},
"componentForEdit": {
"name": "uni-dateformat"
}
}
}
}
{
"bsonType": "object",
"permission": {
"read": "doc.uid == auth.uid && doc.article_status == 0 || doc.article_status == 1",
"create": true,
"update": "doc.uid == auth.uid",
"delete": "doc.uid == auth.uid"
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"user_id": {
"bsonType": "string",
"description": "留言反馈用户ID\/回复留言用户ID,参考uni-id-users表",
"foreignKey": "uni-id-users._id"
},
"create_date": {
"bsonType": "timestamp",
"description": "留言时间\/回复留言时间"
},
"content": {
"bsonType": "string",
"description": "留言内容\/回复内容",
"trim": "right"
},
"imgs": {
"bsonType": "array",
"description": "图片列表"
},
"is_reply": {
"bsonType": "bool",
"description": "是否是回复类型"
},
"feedback_id": {
"bsonType": "string",
"description": "被回复留言ID"
},
"contact": {
"bsonType": "string",
"description": "联系人",
"trim": "both"
},
"mobile": {
"bsonType": "string",
"description": "联系电话",
"trim": "both"
},
"reply_count": {
"bsonType": "int",
"description": "被回复条数"
}
}
}
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"permission": { "permission": {
"read": true, "read": true,
"create": false, "create": false,
"update": false, "update": "doc.uid == auth.uid",
"delete": false "delete": false
}, },
"properties": { "properties": {
......
## 0.0.6(2021-04-01)
- 兼容旧版本安卓
## 0.0.5(2021-04-01)
- 修复低版本安卓上进度条错位
## 0.0.4(2021-04-01)
- 更新readme
- 修复check-update语法错误
## 0.0.3(2021-04-01)
- 新增前台更新弹框,详见readme
- 更新前台检查更新方法
## 0.0.2(2021-03-29)
- 更新文档
- 移除 dependencies
## 0.0.1(2021-03-25)
- 升级中心前台检查更新
{
"id": "uni-upgrade-center-app",
"displayName": "升级中心 uni-upgrade-center - App",
"version": "0.0.6",
"description": "升级中心前台检查更新",
"keywords": [
"uniCloud",
"admin",
"update",
"升级",
"wgt"
],
"repository": "https://gitee.com/dcloud/uni-upgrade-center/tree/master/uni_modules/uni-upgrade-center-app",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"category": [
"uniCloud",
"云端一体页面模板"
],
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "插件不采集任何数据",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "u",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
<template>
<view class="mask flex-center">
<view class="content botton-radius">
<view class="content-top">
<text class="content-top-text">{{title}}</text>
<image class="content-top" style="top: 0;" width="100%" height="100%" src="../static/bg_top.png">
</image>
</view>
<view class="content-header"></view>
<view class="content-body">
<view class="title">
<text>{{subTitle}}</text>
<!-- <text style="padding-left:20rpx;font-size: 0.5em;color: #666;">v.{{version}}</text> -->
</view>
<view class="body">
<scroll-view class="box-des-scroll" scroll-y="true">
<text class="box-des">
{{contents}}
</text>
</scroll-view>
</view>
<view class="footer flex-center">
<template v-if="!downloadSuccess">
<view class="progress-box flex-column" v-if="downloading">
<progress class="progress" border-radius="35" :percent="downLoadPercent"
activeColor="#3DA7FF" show-info stroke-width="10" />
<view style="width:100%;font-size: 28rpx;display: flex;justify-content: space-around;">
<text>{{downLoadingText}}</text>
<text>({{downloadedSize}}/{{packageFileSize}}M)</text>
</view>
</view>
<button v-else class="content-button" style="border: none;color: #fff;" plain
@click="downloadPackage">
{{downLoadBtnText}}
</button>
</template>
<button v-else-if="downloadSuccess && !installed" class="content-button"
style="border: none;color: #fff;" plain :loading="installing" :disabled="installing"
@click="installPackage">
{{installing ? '正在安装……' : '下载完成,立即安装'}}
</button>
<button v-if="installed && isWGT" class="content-button" style="border: none;color: #fff;" plain
@click="restart">
安装完毕,点击重启
</button>
</view>
</view>
<image v-if="!is_mandatory" class="close-img" src="../static/app_update_close.png"
@click.stop="closeUpdate"></image>
</view>
</view>
</template>
<script>
const localFilePathKey = '__localFilePath__'
let downloadTask = null;
/**
* 对比版本号,如需要,请自行修改判断规则
* @param {Object} v1
* @param {Object} v2
* v1 > v2 return 1
* v1 < v2 return -1
* v1 == v2 return 0
*/
function compare(v1 = 0, v2 = 0) {
// '1.2.5' > '1.2.4' 类似的版本号可以直接对比
return v1 > v2 ? 1 : v1 < v2 ? -1 : 0;
}
export default {
data() {
return {
// 从之前下载安装
installForBeforeFilePath: '',
// 安装
installed: false,
installing: false,
// 下载
downloadSuccess: false,
downloading: false,
downLoadPercent: 0,
downloadedSize: 0,
packageFileSize: 0,
tempFilePath: '', // 要安装的本地包地址
// 默认安装包信息
title: '更新日志',
contents: '',
is_mandatory: false,
// 可自定义属性
subTitle: '发现新版本',
downLoadBtnText: '立即下载更新',
downLoadingText: '安装包下载中,请稍后'
}
},
onLoad({
local_storage_key
}) {
if (!local_storage_key) {
console.error('local_storage_key为空,请检查后重试')
uni.navigateBack()
return;
};
const localPackageInfo = uni.getStorageSync(local_storage_key);
if (!localPackageInfo) {
console.error('安装包信息为空,请检查后重试')
uni.navigateBack()
return;
};
const requiredKey = ['version', 'url', 'type']
for (let key in localPackageInfo) {
if (requiredKey.indexOf(key) !== -1 && !localPackageInfo[key]) {
console.error(`参数 ${key} 必填,请检查后重试`)
uni.navigateBack()
return;
}
}
Object.assign(this, localPackageInfo)
this.checkLocalStoragePackage()
},
onBackPress() {
// 强制更新不允许返回
if (this.is_mandatory) {
return true
}
downloadTask && downloadTask.abort()
},
computed: {
isWGT() {
return this.type === 'wgt'
}
},
methods: {
checkLocalStoragePackage() {
// 如果已经有下载好的包,则直接提示安装
const localFilePathRecord = uni.getStorageSync(localFilePathKey)
if (localFilePathRecord) {
const {
version,
savedFilePath
} = localFilePathRecord
// 比对版本
if (compare(version, this.version) === 0) {
this.downloadSuccess = true;
this.installForBeforeFilePath = savedFilePath;
this.tempFilePath = savedFilePath
} else {
// 如果保存的包版本小,则直接删除
this.deleteSavedFile(savedFilePath)
}
}
},
async closeUpdate() {
if (this.downloading) {
if (this.is_mandatory) {
return uni.showToast({
title: '下载中,请稍后……',
icon: 'none',
duration: 500
})
}
uni.showModal({
title: '是否取消下载?',
cancelText: '',
confirmText: '',
success: res => {
if (res.confirm) {
downloadTask && downloadTask.abort()
uni.navigateBack()
}
}
});
return;
}
if (this.downloadSuccess && this.tempFilePath) {
// 包已经下载完毕,稍后安装,将包保存在本地
await this.saveFile(this.tempFilePath, this.version)
uni.navigateBack()
return;
}
uni.navigateBack()
},
downloadPackage() {
this.downloading = true;
//下载包
downloadTask = uni.downloadFile({
url: this.url,
success: res => {
if (res.statusCode == 200) {
this.downloadSuccess = true;
this.tempFilePath = res.tempFilePath
console.log("res.tempFilePath: ", res.tempFilePath);
// 强制更新,直接安装
if (this.is_mandatory) {
this.installPackage();
}
}
},
complete: () => {
this.downloading = false;
this.downLoadPercent = 0
this.downloadedSize = 0
this.packageFileSize = 0
downloadTask = null;
}
});
downloadTask.onProgressUpdate(res => {
this.downLoadPercent = res.progress;
this.downloadedSize = (res.totalBytesWritten / Math.pow(1024, 2)).toFixed(2);
this.packageFileSize = (res.totalBytesExpectedToWrite / Math.pow(1024, 2)).toFixed(2);
});
},
installPackage() {
// #ifdef APP-PLUS
// wgt资源包安装
if (this.isWGT) {
this.installing = true;
}
plus.runtime.install(this.tempFilePath, {
force: false
}, async res => {
this.installing = false;
this.installed = true;
// 如果是安装之前的包,安装成功后删除之前的包
if (this.installForBeforeFilePath) {
await this.deleteSavedFile(this.installForBeforeFilePath)
this.installForBeforeFilePath = '';
}
// wgt包,安装后会提示 安装成功,是否重启
if (this.isWGT) {
// 强制更新安装完成重启
if (this.is_mandatory) {
uni.showLoading({
icon: 'none',
title: '安装成功,正在重启……'
})
setTimeout(() => {
uni.hideLoading()
this.restart();
}, 1000)
} else {
uni.showLoading({
icon: 'none',
title: '安装成功,重启应用体验新版',
duration: 1000
})
}
}
}, async err => {
// 如果是安装之前的包,安装失败后删除之前的包
if (this.installForBeforeFilePath) {
await this.deleteSavedFile(this.installForBeforeFilePath)
this.installForBeforeFilePath = '';
}
// 安装失败需要重新下载安装包
this.installed = false;
uni.showModal({
title: '更新失败',
content: err.message,
showCancel: false
});
});
// 非wgt包,安装跳出覆盖安装,此处直接返回上一页
if (!this.isWGT) {
uni.navigateBack()
}
// #endif
},
restart() {
this.installed = false;
// #ifdef APP-PLUS
//更新完重启app
plus.runtime.restart();
// #endif
},
async saveFile(tempFilePath, version) {
const [err, res] = await uni.saveFile({
tempFilePath
})
if (err) {
return;
}
uni.setStorageSync(localFilePathKey, {
version,
savedFilePath: res.savedFilePath
})
},
deleteSavedFile(filePath) {
uni.removeStorageSync(localFilePathKey)
return uni.removeSavedFile({
filePath
})
}
}
}
</script>
<style>
page {
background: transparent;
}
.flex-center {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
justify-content: center;
align-items: center;
}
.mask {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, .65);
}
.botton-radius {
border-bottom-left-radius: 30rpx;
border-bottom-right-radius: 30rpx;
}
.content {
position: relative;
top: 0;
width: 600rpx;
background-color: #fff;
box-sizing: border-box;
padding: 0 50rpx;
font-family: Source Han Sans CN;
}
.text {
/* #ifndef APP-NVUE */
display: block;
/* #endif */
line-height: 200px;
text-align: center;
color: #FFFFFF;
}
.content-top {
position: absolute;
top: -195rpx;
left: 0;
width: 600rpx;
height: 270rpx;
}
.content-top-text {
font-size: 45rpx;
font-weight: bold;
color: #F8F8FA;
position: absolute;
top: 120rpx;
left: 50rpx;
z-index: 1;
}
.content-header {
height: 70rpx;
}
.title {
font-size: 33rpx;
font-weight: bold;
color: #3DA7FF;
line-height: 38px;
}
.footer {
height: 150rpx;
display: flex;
align-items: center;
justify-content: space-around;
}
.box-des-scroll {
box-sizing: border-box;
padding: 0 40rpx;
height: 200rpx;
text-align: left;
}
.box-des {
font-size: 26rpx;
color: #000000;
line-height: 50rpx;
}
.progress-box {
width: 100%;
}
.progress {
width: 90%;
height: 40rpx;
border-radius: 35px;
}
.close-img {
width: 70rpx;
height: 70rpx;
z-index: 1000;
position: absolute;
bottom: -120rpx;
left: calc(50% - 70rpx / 2);
}
.content-button {
text-align: center;
flex: 1;
font-size: 30rpx;
font-weight: 400;
color: #FFFFFF;
height: 80rpx;
line-height: 80rpx;
background: url(../static/button_bg.png) no-repeat center/contain;
}
.flex-column {
display: flex;
flex-direction: column;
align-items: center;
}
</style>
# uni-upgrade-center - App
### 概述
> 统一管理App及App在`Android`、`iOS`平台上`App安装包`和`wgt资源包`的发布升级
> 本插件为升级中心前台检查更新,后台Admin管理系统请点击查看 [uni-upgrade-center](https://ext.dcloud.net.cn/plugin?id=4470)
### 基于uni-upgrade-center的App前台检查升级插件
- 一键式检查更新,统一整包与wgt资源包更新
- 好看、实用、可自定义、可拓展的前台更新弹框
## 安装指引
1. 使用`HBuilderX 3.1.0+`,因为要使用到`uni_modules`
3. 在插件市场打开本插件页面,在右侧点击`使用 HBuilderX 导入插件`,选择要导入的项目点击确定
5. 找到`/uni_modules/uni-upgrade-center-app/uniCloud/cloudfunctions/check-version`,右键上传部署
6.`pages.json`中添加页面路径
```json
"pages": [
// ……其他页面配置
{
"path": "uni_modules/uni-upgrade-center-app/pages/upgrade-popup",
"style": {
"disableScroll": true,
"app-plus": {
"backgroundColorTop": "transparent",
"background": "transparent",
"titleNView": false,
"scrollIndicator": false,
"popGesture": "none",
"animationType": "fade-in",
"animationDuration": 200
}
}
}
]
```
7.`/uni_modules/uni-upgrade-center-app/utils/check-update`import到需要用到的地方,调用一下即可
### 更新下载安装`check-update.js`
*该函数在utils目录下*
1. 如果是静默更新,则不会打开更新弹框,会在后台下载后安装,下次启动应用生效
2. 如果是 iOS,则会直接打开AppStore的链接
3. 其他情况,会将`check-version`返回的结果保存在localStorage中,并跳转进入`upgrade-popup.vue`打开更新弹框
### 检查更新函数`check-version`
*该函数在uniCloud/cloudfunctions目录下*
1. 使用检查更新需要传递三个参数 `appid``appVersion``wgtVersion`
2. `appid` 使用 plus.runtime.appid 获取,*注:真机运行时为固定值HBuilder,在调试的时候请使用本地调试云函数*
3. `appVersion` 使用 plus.runtime.version 获取
4. `wgtVersion` 使用 plus.runtime.getProperty(plus.runtime.appid,(wgtInfo) => { wgtInfo.version }) 获取
5. `check-version`云函数内部会自动获取 App 平台
6. 检查更新前端使用示例:`uni_modules/uni-upgrade-center-app/utils/check-update.js`,在要用的地方导入调用即可
## 项目代码说明
### 更新弹框
- `upgrade-popup.vue` - 更新应用:
- 如果`check-version`返回的参数表明需要更新,则将参数保存在localStorage中,带着键值跳转该页面
- 进入时会先从localStorage中尝试取出之前存的安装包路径(此包不会是强制安装类型的包)
- 如果有已经保存的包,则和传进来的 `version` 进行比较,如果相等则安装。大于和小于都不进行安装,因为admin端可能会调整包的版本。不符合更新会将此包删除
- 如果本地没有包或者包不符合安装条件,则进行下载安装包
- 点击下载会有进度条、已下载大小和下载包的大小
- 下载完成会提示安装:
- 如果是 wgt 包,安装时则会提示 正在安装…… 和 安装完成。安装完成会提示是否重启
- 如果是 原生安装包,则直接跳出去覆盖安装
- 下载过程中,如果退出会提示是否取消下载。如果是强制更新,则只会提示正在下载请稍后,此时不可退出
- 如果是下载完成了没有安装就退出,则会将下载完成的包保存在本地。将包的本地路径和包version保存在localStorage中
### 云函数
- `check-version` - 检查应用更新:
- 根据传参,先检测传参是否完整,appid appVersion wgtVersion 必传
- 先从数据库取出所有该平台(会从上下文读取平台信息)的所有线上发行更新
- 再从所有线上发行更新中取出版本最大的一版。如果可以,尽量先检测wgt的线上发行版更新
- 使用上一步取出的版本包的版本号 和传参 appVersion、wgtVersion 来检测是否有更新。必须同时大于这两项,因为上一次可能是wgt热更新,否则返回暂无更新
- 如果库中 wgt包 版本大于传参 appVersion,但是不满足 min_uni_version < appVersion,则不会使用wgt更新,会接着判断库中 app包version 是否大于 appVersion
\ No newline at end of file
// 本文件中的json内容将在云函数【运行】时作为参数传给云函数。
// 配置教程参考:https://uniapp.dcloud.net.cn/uniCloud/quickstart?id=runparam
{
"appid": "__YOUR_APPID__",
"appVersion": "2.2.0",
"wgtVersion": "2.2.2"
}
'use strict';
exports.main = async (event, context) => {
/**
* 检测升级 使用说明
* 上传包:
* 1. 根据传参,先检测传参是否完整,appid appVersion wgtVersion 必传
* 2. 先从数据库取出所有该平台(从上下文读取平台信息,默认 Andriod)的所有线上发行更新
* 3. 再从所有线上发行更新中取出版本最大的一版。如果可以,尽量先检测wgt的线上发行版更新
* 4. 使用上步取出的版本包的版本号 和传参 appVersion、wgtVersion 来检测是否有更新,必须同时大于这两项,否则返回暂无更新
* 5. 如果库中 wgt包 版本大于传参 appVersion,但是不满足 min_uni_version < appVersion,则不会使用wgt更新,会接着判断库中 app包version 是否大于 appVersion
*/
let {
appid,
appVersion,
wgtVersion,
} = event;
const platform_Android = 'Android';
const platform_iOS = 'iOS';
const package_app = 'native_app';
const package_wgt = 'wgt';
const app_version_db_name = 'opendb-app-versions'
let platform = platform_Android;
// 云函数URL化请求
if (event.headers) {
let body;
try {
if (event.httpMethod.toLocaleLowerCase() === 'get') {
body = event.queryStringParameters;
} else {
body = JSON.parse(event.body);
}
} catch (e) {
return {
code: 500,
msg: '请求错误'
};
}
appid = body.appid;
appVersion = body.appVersion;
wgtVersion = body.wgtVersion;
platform = /iPhone|iPad/.test(event.headers) ? platform_iOS : platform_Android;
} else if (context.OS) {
platform = context.OS === 'android'
? platform_Android
: context.OS === 'ios'
? platform_iOS
: platform_Android;
}
if (appid && appVersion && wgtVersion && platform) {
const collection = uniCloud.database().collection(app_version_db_name);
const record = await collection.where({
appid,
platform,
stable_publish: true
})
.orderBy('create_date', 'desc')
.get();
if (record && record.data && record.data.length > 0) {
const appVersionInDb = record.data.find(item => item.type === package_app) || {};
const wgtVersionInDb = record.data.find(item => item.type === package_wgt) || {};
const hasAppPackage = !!Object.keys(appVersionInDb).length;
const hasWgtPackage = !!Object.keys(wgtVersionInDb).length;
// 取两个版本中版本号最大的包,版本一样,使用wgt包
let stablePublishDb = hasAppPackage
? hasWgtPackage
? compare(wgtVersionInDb.version, appVersionInDb.version) >= 0
? wgtVersionInDb
: appVersionInDb
: appVersionInDb
: wgtVersionInDb;
const {
version,
min_uni_version
} = stablePublishDb;
// 库中的version必须满足同时大于appVersion和wgtVersion才行,因为上次更新可能是wgt更新
const appUpdate = compare(version, appVersion) === 1; // app包可用更新
const wgtUpdate = compare(version, wgtVersion) === 1; // wgt包可用更新
if (Object.keys(stablePublishDb).length && appUpdate && wgtUpdate) {
// 判断是否可用wgt更新
if (min_uni_version && compare(min_uni_version, appVersion) < 1) {
return {
code: 101,
message: 'wgt更新',
...stablePublishDb
};
} else if (hasAppPackage && compare(appVersionInDb.version, appVersion) === 1) {
return {
code: 102,
message: '整包更新',
...appVersionInDb
};
}
}
return {
code: 0,
message: '当前版本已经是最新的,不需要更新'
};
}
return {
code: -101,
message: '暂无更新或检查appid是否填写正确'
};
}
return {
code: -102,
message: '请检查传参是否填写正确'
};
};
/**
* 对比版本号,如需要,请自行修改判断规则
* @param {Object} v1
* @param {Object} v2
* v1 > v2 return 1
* v1 < v2 return -1
* v1 == v2 return 0
*/
function compare(v1 = 0, v2 = 0) {
// '1.2.5' > '1.2.4' 类似的版本号可以直接对比
return v1 > v2 ? 1 : v1 < v2 ? -1 : 0;
}
// 推荐再App.vue中使用
const PACKAGE_INFO_KEY = '__package_info__'
export default function() {
// #ifdef APP-PLUS
plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
uniCloud.callFunction({
name: 'check-version',
data: {
appid: plus.runtime.appid,
appVersion: plus.runtime.version,
wgtVersion: widgetInfo.version
},
success: (e) => {
if (!e.result) return;
const {
code,
message,
is_silently, // 是否静默更新
url, // 安装包下载地址
platform, // 安装包平台
type // 安装包类型
} = e.result;
// 此处逻辑仅为实例,可自行编写
if (code > 0) {
// 静默更新,只有wgt有
if (is_silently) {
downloadTask = uni.downloadFile({
url: this.url,
success: res => {
if (res.statusCode == 200) {
// 下载好直接安装,下次启动生效
plus.runtime.install(res.tempFilePath, {
force: false
});
}
}
});
return;
}
if (type === 'native_app' && platform.includes('iOS')) {
// iOS 跳转 AppStore 商店
plus.runtime.openURL(url);
return;
}
uni.setStorageSync(PACKAGE_INFO_KEY, e.result)
// 跳转更新页面
uni.navigateTo({
url: '/uni_modules/uni-upgrade-center-app/pages/upgrade-popup?local_storage_key=' +
PACKAGE_INFO_KEY,
fail: (err) => {
console.error('更新弹框跳转失败', err)
uni.removeStorageSync(PACKAGE_INFO_KEY)
}
})
} else if (code < 0) {
// TODO 云函数报错处理
console.error(message)
}
},
fail: (err) => {
// TODO 云函数报错处理
console.error(err.message)
}
})
});
// #endif
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册