<template>
|
<view class="pages-login">
|
<view class="uni-panel-content items-center">
|
|
<view class="login-content">
|
<view class="items-center">
|
<!-- <image class="title-img" src="/images/earth.svg" alt=" 图片" /> -->
|
|
</view>
|
<text class="title">{{translate('start_login')}}</text>
|
<view class="login-form">
|
<view class="login-form-item line">
|
<text class="label">{{translate('account')}}</text>
|
<input class="input" :focus="formData.accountFocus" comfirm-type="done" type="text"
|
v-model="form.account" :placeholder="translate('input_login')" />
|
</view>
|
|
<view class="login-form-item line">
|
<text class="label">{{translate('password')}}</text>
|
<input class="input" :focus="formData.passwordFocus" :password="hidePassContent"
|
comfirm-type="done" v-model="form.password" :placeholder="translate('input_password')" />
|
<uni-icons :type="hidePassContent?'eye-slash':'eye'" size="28"
|
@click="clickHidePassContent"></uni-icons>
|
</view>
|
<view class="login-form-item">
|
<checkbox-group @change="handleSavePwdChange">
|
<label>
|
<checkbox value="1" :checked="savePsw" />
|
<text>{{translate('remember_password')}}</text>
|
</label>
|
</checkbox-group>
|
|
|
<!-- <a @click="clickForgotPassword">忘记密码</a> -->
|
</view>
|
<view class="button-group">
|
<a-button :disabled="disabledOk" type="primary" class="button"
|
@click="clickLogin">{{translate('login')}}</a-button>
|
<!-- <a-button class="button" type="ghost" @click="clickNewAccount">创建账号</a-button> -->
|
</view>
|
</view>
|
|
</view>
|
</view>
|
<view class="bottom">
|
<a class="language" @click="clickLanguage">{{translate("language")}}</a>
|
<view class="version">
|
{{translate("version")}}:{{version.date}}_{{version.ver}}
|
</view>
|
</view>
|
<!-- 版本升级弹窗开始 -->
|
<uni-popup ref="promotion" type="center">
|
<view class="promotion" style="width: 700rpx;padding:20rpx 40rpx; background: white;font-size: 36rpx;">
|
|
<view class="operates">
|
<view v-if="showUpdateBtns" style="text-align: center;padding:20rpx;font-weight: 700;">
|
{{translate('ask_update') }}
|
</view>
|
<view style="text-align: center;padding-top:20rpx;">
|
{{carUpdateFlag ? translate('tip_car_update') : translate('tip_app_update') }}:{{newVersion.date}}_{{newVersion.ver}}
|
</view>
|
<view v-if="newVersion.info" style="padding:20rpx;font-weight: 600;">
|
{{translate("version_info")}}:{{newVersion.info}}
|
</view>
|
|
<template v-if="showUpdateBtns">
|
<text @click="onCancel"
|
style="margin-top:30rpx; display: inline-block;color: #7cd0f8;width: 50%; text-align: center;">{{translate('cancel')}}</text>
|
<text @click="onUpdate"
|
style="margin-top:30rpx;display: inline-block;color: #7cd0f8;width: 50%; text-align: center;">{{translate('confirm')}}</text>
|
</template>
|
</view>
|
<view class="operates" v-if=" !showUpdateBtns">
|
<cmdProgress :percent="percentage" stroke-color="linear-gradient(to right, #ef32d9, #89fffd)">
|
</cmdProgress>
|
</view>
|
</view>
|
</uni-popup>
|
</view>
|
</template>
|
|
<script>
|
import cmdProgress from "@/components/cmd-progress/index.vue"
|
import {
|
session,
|
showToast,
|
showModal,
|
showError
|
} from "@/comm/utils.js"
|
import TaskInit from "@/comm/extend.js"
|
import {
|
Button
|
} from 'antd-mobile-vue-next'
|
import {
|
getAppVersion,
|
getServerVersion,
|
downloadUpdatePackage
|
} from "@/api/version.js"
|
|
|
|
export default {
|
name: "PagesLogin",
|
components: {
|
'a-button': Button,
|
cmdProgress
|
},
|
data() {
|
|
return {
|
form: {
|
account: '',
|
password: ''
|
},
|
formData: {
|
accountFocus: true,
|
passwordFocus: false
|
},
|
hidePassContent: true,
|
savePsw: false,
|
version: {
|
date: "",
|
ver: ""
|
},
|
newVersion: {
|
date: "",
|
ver: "",
|
info:""
|
},
|
carUpdateFlag: false,
|
vesironFileName: "", //安卓app下载链接
|
percentage: 0, //下载进度
|
showUpdateBtns: true,
|
}
|
},
|
computed: {
|
disabledOk() {
|
// let text = this.form.account.trim()
|
// if (!text) {
|
// return true
|
// }
|
// text = this.form.password.trim()
|
// if (!text) {
|
// return true
|
// }
|
return false
|
}
|
},
|
onLoad(option) {
|
const _this = this
|
uni.setNavigationBarTitle({
|
title: this.translate('login')
|
})
|
|
uni.getSystemInfo({
|
success(e) {
|
const app = getApp()
|
app.globalData.platform = e.platform
|
app.globalData.deviceModel = e.deviceModel
|
app.globalData.osVersion = parseInt(e.osVersion)
|
console.log(e)
|
},
|
|
})
|
const info = session.getValue("login_info")
|
|
this.setData({
|
form: {
|
account: info?.id || '',
|
password: info?.password || ''
|
|
},
|
savePsw: info?.savePsw || false
|
})
|
// #ifdef APP-PLUS
|
plus.runtime.getProperty(plus.runtime.appid, (info) => {
|
// console.log(info);
|
const verStr = info.version || "";
|
const arVer = verStr.split("_")
|
if (arVer.length > 1) {
|
_this.version = {
|
date: arVer[0],
|
ver: arVer[1]
|
}
|
} else if (arVer.length == 1) {
|
_this.version = {
|
date: "",
|
ver: arVer[0]
|
}
|
}
|
if (!option.flag)
|
_this.checkAppVersion(_this.version)
|
|
});
|
//#endif
|
|
},
|
methods: {
|
setData(obj) {
|
let that = this;
|
let keys = [];
|
let val, data;
|
|
Object.keys(obj).forEach(function(key) {
|
keys = key.split(".");
|
val = obj[key];
|
data = that.$data;
|
keys.forEach(function(key2, index) {
|
if (index + 1 == keys.length) {
|
that.$set(data, key2, val);
|
} else {
|
if (!data[key2]) {
|
that.$set(data, key2, {});
|
}
|
}
|
data = data[key2];
|
});
|
});
|
},
|
|
clickLanguage() {
|
uni.navigateTo({
|
url: "/pages/my/language"
|
})
|
|
},
|
clickHidePassContent() {
|
this.hidePassContent = !this.hidePassContent
|
},
|
handleSavePwdChange(e) {
|
|
if (e.detail.value[0] == '1') {
|
this.savePsw = true
|
} else {
|
this.savePsw = false
|
}
|
|
},
|
onUpdate() {
|
this.showUpdateBtns = false;
|
|
|
this.updateAPP(this.vesironFileName, this.newVersion)
|
},
|
onCancel() {
|
this.$refs.promotion.close();
|
if (!this.carUpdateFlag) {
|
setTimeout(() => {
|
this.checkServerVersion()
|
}, 500)
|
}
|
|
},
|
updateAPP(fileName, verInfo) {
|
let _this = this;
|
let sys = uni.getSystemInfoSync().platform //检查系统
|
|
downloadUpdatePackage(fileName, (path) => {
|
if (_this.carUpdateFlag) {
|
var pathArr = fileName.split(".")
|
const fileExt = pathArr.pop()
|
const fileName2 = `EasyGO_${verInfo.date}_${verInfo.ver}.${fileExt}`
|
TaskInit.fileUtils.clearSavedFiles("car_version")
|
TaskInit.fileUtils.moveToLocal(path, "car_version", fileName2).then((
|
res) => {
|
console.log("保存成功:", res)
|
showToast(this.translate('download_success'));
|
}).catch((err) => {
|
console.log("保存失败:", err)
|
showToast(_this.translate("failed_save_file"))
|
})
|
} else {
|
plus.runtime.openFile(path); //选择软件打开文件
|
showToast(this.translate('update_success'));
|
}
|
_this.$refs.promotion.close();
|
|
}, (res) => {
|
console.log('下载进度' + res.progress);
|
_this.percentage = res.progress
|
if (_this.percentage == 100) {
|
_this.$refs.promotion.close();
|
}
|
}, (err) => {
|
_this.$refs.promotion.close();
|
showToast(`${_this.translate('update_fail') },${err}`);
|
})
|
|
},
|
async checkAppVersion(version) {
|
try {
|
const listVer = await getAppVersion() || []
|
const appVer = listVer[0] || {}
|
this.vesironFileName = appVer.file_name || ""
|
if (this.vesironFileName) {
|
var isver = this.compareVersion({
|
date: appVer.file_time,
|
ver: appVer.version
|
}, version);
|
|
if (isver) {
|
this.carUpdateFlag = false
|
this.newVersion = {
|
date: appVer.file_time,
|
ver: appVer.version,
|
info: appVer.info,
|
}
|
this.$refs.promotion.open();
|
} else {
|
this.checkServerVersion()
|
}
|
} else {
|
this.checkServerVersion()
|
}
|
} catch (ex) {
|
console.log(ex)
|
}
|
|
},
|
getVersionFromFileName(fileName) {
|
if (!fileName.trim()) {
|
return {
|
date: "",
|
ver: ""
|
}
|
}
|
let versionInfos = fileName.trim().split('_');
|
let date = versionInfos[1]
|
let version2 = versionInfos[2]
|
let versionInfos2 = version2.split('.');
|
versionInfos2.pop()
|
return {
|
date,
|
ver: versionInfos2.join(".")
|
}
|
},
|
compareVersion(curV, reqV) {
|
|
if (curV.date == reqV.date) {
|
return curV.ver > reqV.ver
|
}
|
return curV.date > reqV.date
|
},
|
async checkServerVersion() {
|
try {
|
const listVer = await getServerVersion() || []
|
const svrVer = listVer[0] || {}
|
this.vesironFileName = svrVer.file_name || ""
|
if (this.vesironFileName) {
|
var oldVerName = ""
|
var fileList = []
|
try {
|
fileList = await TaskInit.fileUtils.listSavedFiles('car_version')
|
} catch (ex) {
|
console.log(ex)
|
}
|
fileList.forEach((ele) => {
|
if (oldVerName) {
|
if (oldVerName < ele.name) {
|
oldVerName = ele.name
|
}
|
} else {
|
oldVerName = ele.name
|
}
|
})
|
console.log(oldVerName)
|
if (oldVerName) {
|
const oldVer = this.getVersionFromFileName(oldVerName)
|
const isVer = this.compareVersion({
|
date: svrVer.file_time,
|
ver: svrVer.version
|
}, oldVer);
|
if (isVer || !oldVer) {
|
this.carUpdateFlag = true
|
this.newVersion = {
|
date: svrVer.file_time,
|
ver: svrVer.version,
|
info: svrVer.info,
|
}
|
this.$refs.promotion.open();
|
}
|
} else {
|
this.carUpdateFlag = true
|
this.newVersion = {
|
date: svrVer.file_time,
|
ver: svrVer.version,
|
info: svrVer.info,
|
}
|
this.$refs.promotion.open();
|
}
|
|
}
|
} catch (ex) {
|
|
console.log(ex)
|
}
|
|
},
|
|
async clickLogin() {
|
|
try {
|
let account = this.form.account.trim()
|
if (!account) {
|
showToast(this.translate("input_login"))
|
return
|
}
|
let password = this.form.password.trim()
|
if (!password) {
|
showToast(this.translate("input_password"))
|
return
|
}
|
if (account != "sa") {
|
showToast(this.translate("account_not_exist"))
|
return
|
}
|
if (password != "0000") {
|
showToast(this.translate("password_error"))
|
return
|
}
|
if (this.savePsw) {
|
|
session.setValue("login_info", {
|
id: account,
|
password,
|
savePsw: true,
|
})
|
} else {
|
session.setValue("login_info", {
|
id: account,
|
password: ""
|
})
|
}
|
getApp().globalData.withLog = session.getValue("write_log") ? true : false
|
uni.reLaunch({
|
url: "/pages/index/index"
|
})
|
// uni.navigateTo({
|
// url: `/pages/index/connect?ip=192.168.1.2&sid=HH&password=HH888888`
|
// })
|
} catch (ex) {
|
showError(ex)
|
}
|
},
|
clickNewAccount() {
|
uni.navigateTo({
|
url: "/pages/login/register"
|
})
|
},
|
clickForgotPassword() {
|
uni.navigateTo({
|
url: "/pages/login/forgot-password"
|
})
|
},
|
translate(t) {
|
if (typeof this.$t == "function") return this.$t(`page.${t}`)
|
else return t;
|
},
|
},
|
|
}
|
</script>
|
|
<style lang="scss">
|
.pages-login {
|
display: flex;
|
width: 750rpx;
|
height: 100vh;
|
flex-direction: column;
|
|
.uni-panel-content {
|
display: flex;
|
flex: 1;
|
width: 750rpx;
|
flex-direction: column;
|
}
|
|
.bottom {
|
width: calc(100% - 40rpx);
|
padding: 10rpx 20rpx;
|
|
.version {
|
float: right;
|
color: #888;
|
flex-direction: row;
|
display: flex;
|
}
|
|
.language {
|
float: left;
|
display: flex;
|
text-decoration: underline;
|
/* 下划线 */
|
}
|
}
|
|
.login-content {
|
width: 750rpx;
|
display: flex;
|
flex-direction: column;
|
}
|
|
.justify-center {
|
justify-content: center;
|
}
|
|
.items-center {
|
align-items: center
|
}
|
|
.title-img {
|
display: block;
|
margin: auto;
|
width: 300rpx;
|
height: 300rpx;
|
}
|
|
.title {
|
font-size: 40rpx;
|
margin: auto;
|
padding: 100rpx;
|
}
|
|
.login-form {
|
display: flex;
|
padding: 20rpx 40rpx;
|
flex-direction: column;
|
}
|
|
.login-form-item {
|
padding: 10rpx;
|
display: flex;
|
margin: 20rpx 10rpx;
|
font-size: 28rpx !important;
|
flex-direction: row;
|
|
|
.label {
|
text-align: right;
|
width: 120rpx;
|
margin-top: 15rpx;
|
}
|
|
.input {
|
flex: 1;
|
margin: 10rpx 20rpx 15rpx 20rpx;
|
}
|
|
}
|
|
.line {
|
border-bottom: 2rpx solid #ddd;
|
}
|
|
.button-group {
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
flex-direction: column;
|
font-size: 30rpx !important;
|
padding: 100rpx;
|
|
.am-button {
|
border-radius: 30px;
|
}
|
|
.am-button-ghost {
|
border: 1px solid #1677ff !important;
|
|
}
|
}
|
|
.button {
|
margin: auto;
|
margin-top: 20rpx;
|
width: 500rpx;
|
|
}
|
|
|
}
|
</style>
|