login.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <template>
  2. <view class="normal-login-container">
  3. <view style="color: aliceblue;position: fixed;left: 10px;z-index: 999999;top:50px;font-size: 10px;">{{i18('版本')}}:{{version}}</view>
  4. <view style="color: aliceblue;position: fixed;right: 10px;z-index: 999999;top:50px" @click="changeLocale">
  5. {{ $t('login.language') }}:{{localeConfig[locale]}}<uni-icons type="gear" size="15"></uni-icons>
  6. </view>
  7. <view style="height: 30vh;">
  8. <image style="height: 3vh;width: 15vh;margin-top: 20vh;margin-left: 15vh;" src="../static/images/new/starts/login/backImg2.png"></image>
  9. </view>
  10. <view style="height: 40vh;">
  11. <!-- <image style="width: 750px;height: 807px;" :src="imgUrl+'/login/backImg2.png'" mode="widthFix"/> -->
  12. <!-- <view class="logo-content align-center justify-center flex">
  13. <text class="title" style="font-size: 25px;margin-left:-71px">{{$t('login.title') }}</text>
  14. </view> -->
  15. <view class="logo-content justify-center flex">
  16. <text class="welcome" style="height: 20vh;">Welcome</text>
  17. </view>
  18. </view>
  19. <!-- 登录表单 -->
  20. <view class="login-form-content" style="z-index: 99;position: relative;" v-show="isLogin">
  21. <view class="input-item flex align-center" v-if="locale == 'en'">
  22. <!-- <view class="iconfont icon-user icon"></view> -->
  23. <uni-row>
  24. <uni-col :span="2">
  25. <uni-icons class="icon" type="email" size="20" color="#e3e3e3"></uni-icons>
  26. </uni-col>
  27. <uni-col :span="22">
  28. <input style="color: #000000;" v-model="loginForm.username" class="input" type="text" :placeholder="$t('login.mailInput')" maxlength="30" />
  29. </uni-col>
  30. </uni-row>
  31. </view>
  32. <view class="input-item flex align-center" v-if="locale == 'en'">
  33. <!-- <view class="iconfont icon-password icon"></view> -->
  34. <uni-row
  35. <uni-col :span="2">
  36. <uni-icons class="icon" type="locked-filled" size="20" color="#e3e3e3"></uni-icons>
  37. </uni-col>
  38. <uni-col :span="18">
  39. <uni-easyinput style="margin-left:-10px ;color: #000000;" :inputBorder="false" v-model="loginForm.password" type="password" class="input" :placeholder="$t('login.pwdInput')" maxlength="30" />
  40. </uni-col>
  41. </uni-row>
  42. </view>
  43. <view class="xieyi text-center" style="margin-top: -10px;" v-if="locale == 'en'">
  44. <text class="text-grey">{{ $t('login.noAccount') }},</text>
  45. <text @click="toggleLoginMode" class="text-green">{{ $t('login.resiger') }}</text>
  46. <!-- <text @click="handleUserAgrement" class="text-green">立即注册</text> -->
  47. <!-- <text @click="handlePrivacy" class="text-blue">《隐私协议》</text> -->
  48. </view>
  49. <!-- <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
  50. <view class="iconfont icon-code icon"></view>
  51. <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  52. <view class="login-code"> <image :src="codeUrl" @click="getCode" class="login-code-img"></image></view >
  53. </view> -->
  54. <view class="text-green" style="margin: 5px 0;margin-top:15px;font-size: 12px;;" @click="forgetPwd">{{i18('忘记密码?')}}</view>
  55. <view class="action-btn" style="z-index: 99;position: relative;">
  56. <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">{{ $t('login.tologin') }}</button>
  57. </view>
  58. </view>
  59. <view class="login-form-content" style="z-index: 9999;position: relative;" v-show="!isLogin" @submit.prevent="handleRegister">
  60. <!-- 注册表单 -->
  61. <view>
  62. <view class="input-item flex align-center">
  63. <uni-row>
  64. <uni-col :span="2">
  65. <uni-icons class="icon" type="email" size="20" color="#e3e3e3"></uni-icons>
  66. </uni-col>
  67. <uni-col :span="22">
  68. <input style="color: #000000;" v-model="register.username" class="input" type="text" :placeholder="$t('login.mailInput')" maxlength="30" />
  69. </uni-col>
  70. </uni-row>
  71. </view>
  72. <view>
  73. <view class="input-item flex align-center">
  74. <uni-row>
  75. <uni-col :span="2">
  76. <uni-icons class="icon" type="locked" size="20" color="#e3e3e3"></uni-icons>
  77. </uni-col>
  78. <uni-col :span="22">
  79. <input v-model="register.password" style="color: #000000;" class="input" type="text" :placeholder="$t('login.pwdInput')" maxlength="30" />
  80. </uni-col>
  81. </uni-row>
  82. </view>
  83. </view>
  84. <view class="xieyi text-center" style="margin-top: -10px;">
  85. <p class="text-grey">{{ $t('register.hasAccount') }}<a href="#" @click="toggleLoginMode" class="text-green">{{ $t('register.backLogin') }}</a></p>
  86. </view>
  87. <view class="action-btn" style="z-index: 9999;position: relative;">
  88. <button @click="handleRegister" type="submit" class="login-btn cu-btn block bg-blue lg round">{{ $t('register.register') }}</button>
  89. </view>
  90. </view>
  91. </view>
  92. <!-- <view v-show="isLogin">
  93. <view class="img">
  94. <image @click="buleTeeth" style="width: 31px;" :src="imgUrl+'/login/blueTeeth.png'" mode="widthFix"/>
  95. </view>
  96. <view class="blue-text">
  97. <text @click="buleTeeth">{{ $t('login.buletooth') }}</text>
  98. </view>
  99. </view> -->
  100. <u-picker @cancel="cancelLocale" :confirmText="i18('确认')" :cancelText="i18('取消')" :show="showLocale" keyName="label" :columns="localeList" @confirm="changeLanguage"></u-picker>
  101. <u-popup :zoom="false" :show="showStatus" :mask-close-able="false" mode="center" :closeable="false" border-radius="14" height="150rpx">
  102. <view style="margin:20rpx">
  103. {{i18('检测到有新版本,请点击下载')}} {{newVerson}}
  104. </view>
  105. <view v-if="!isShowProgress" style="text-align: center;text-decoration: underline;margin:10px" @click="downloadFile">
  106. {{i18('立即下载')}}
  107. </view>
  108. <view class="progress-container" v-if="isShowProgress">
  109. <view class="progress-box">
  110. <view class="text"> {{i18('文件下载中,请稍后......')}}</view>
  111. <progress :percent="progress" show-info stroke-width="3" />
  112. </view>
  113. </view>
  114. </u-popup>
  115. <u-popup :show="showCode" :round="10" mode="center" @close="closeCode">
  116. <view style="border-radius: 10px;
  117. width: 250px;">
  118. <image style="border-radius: 10px" src="/static/images/new/code.jpg" mode="widthFix"/>
  119. </view>
  120. </u-popup>
  121. </view>
  122. </template>
  123. <script>
  124. import {checkVersion,forgetPwd} from '@/api/login'
  125. import {getToken} from "@/utils/auth";
  126. import i18 from '@/utils/i18.js'
  127. export default {
  128. data() {
  129. return {
  130. version:"",
  131. newVerson:"",
  132. showLocale:false,
  133. localeList:[[{"label":"简体中文","id":"zh-Hans"},{"label":"英文","id":"en"}]],
  134. localeConfig:{"zh-Hans":"简体中文","en":"英文"},
  135. // currentImg: "",
  136. codeUrl: "",
  137. captchaEnabled: true,
  138. globalConfig: getApp().globalData.config,
  139. loginForm: {
  140. username: "",
  141. password: "",
  142. code: "",
  143. uuid: ''
  144. },
  145. register: {
  146. username: "",
  147. password: "",
  148. locale: "",
  149. },
  150. appVersionCode: "",
  151. showStatus: false,
  152. downloadUrl: "",
  153. iosUrl: "",
  154. isShowProgress: false,
  155. progress: 0,
  156. isLogin: true, // 是否为登录模式
  157. showCode: false,
  158. platom:""
  159. }
  160. },
  161. // mounted() {
  162. // this.addTextEvent()
  163. // },
  164. computed: {
  165. imgUrl: function () {
  166. return getApp().globalData.config.imgUrl;
  167. }
  168. },
  169. created() {
  170. let self = this;
  171. uni.getSystemInfo({
  172. success:function(res){
  173. self.platom = res.platform;
  174. self.checkVersion();
  175. }
  176. });
  177. this.setLocale()
  178. uni.getLocation({
  179. type: 'wgs84',
  180. success: function (res) {
  181. console.log('当前位置的经度:' + res.longitude);
  182. console.log('当前位置的纬度:' + res.latitude);
  183. }
  184. });
  185. this.checkLogin();
  186. this.readLoginInfo()
  187. },
  188. methods: {
  189. readLoginInfo(){
  190. let loginForm = uni.getStorageSync("loginInfo");
  191. if(loginForm){
  192. this.loginForm = loginForm;
  193. this.pwdLogin()
  194. }
  195. },
  196. saveLoginInfo(){
  197. if(this.loginForm.username.length>0){
  198. uni.setStorageSync("loginInfo",this.loginForm);
  199. }
  200. },
  201. forgetPwd(){
  202. let self = this;
  203. uni.showModal({
  204. editable:true,
  205. title: i18('请输入邮箱'),
  206. success: function (res) {
  207. if (res.confirm) {
  208. let mail = res.content;
  209. if(!mail){
  210. uni.showToast({
  211. title: i18('邮箱不能为空'),
  212. icon: 'none'
  213. })
  214. return;
  215. }
  216. forgetPwd(mail,self.locale).then(res=>{
  217. if(res.data){
  218. uni.showToast({
  219. title: i18('请查看邮箱进行操作'),
  220. icon: 'none'
  221. })
  222. }else{
  223. uni.showToast({
  224. title: msg,
  225. icon: 'none'
  226. })
  227. }
  228. });
  229. } else if (res.cancel) {
  230. console.log('用户点击取消');
  231. }
  232. }
  233. });
  234. },
  235. closeCode(){
  236. this.showCode = false
  237. },
  238. i18(text){
  239. return i18(text)
  240. },
  241. downloadFile(){
  242. let self = this;
  243. const platform = this.platom.toLowerCase();
  244. if (platform == 'android') {
  245. let downUrl = self.downloadUrl;
  246. plus.runtime.openURL(downUrl);
  247. }else{
  248. const appleId = '86726R3L5K'; // 这里替换成你的 apple id
  249. plus.runtime.launchApplication({
  250. action: self.iosUrl
  251. },
  252. function(e) {
  253. console.log('Open system default browser failed: ' + e.message);
  254. }
  255. );
  256. }
  257. // self.isShowProgress = true;
  258. // const downloadTask = uni.downloadFile({
  259. // url: self.downloadUrl,
  260. // success: res => {
  261. // if (res.statusCode === 200) {
  262. // this.isShowProgress = false;
  263. // console.log('下载成功');
  264. // }
  265. // let that = this;
  266. // plus.runtime.install(res
  267. // .tempFilePath, {
  268. // force: false
  269. // },
  270. // function() {
  271. // plus.runtime
  272. // .restart();
  273. // });
  274. // }
  275. // })
  276. // console.log(downloadTask)
  277. // downloadTask.onProgressUpdate((res) => {
  278. // if(res.progress > 0) {
  279. // this.isShowProgress = true;
  280. // }
  281. // this.progress = res.progress;
  282. // console.log('下载进度:' + res.progress);
  283. // console.log('已下载长度:' + res.totalBytesWritten);
  284. // console.log('文件总长度:' + res.totalBytesExpectedToWrite);
  285. // })
  286. },
  287. checkVersion(){
  288. let appBaseInfo = uni.getAppBaseInfo();
  289. let appVersionCode = appBaseInfo.appVersionCode;
  290. this.appVersionCode = appVersionCode;
  291. this.version = appVersionCode;
  292. let self = this;
  293. checkVersion({"versionCode":appVersionCode,"platom":this.platom}).then(res=>{
  294. let cz_app_version =res.data;
  295. console.log(cz_app_version)
  296. if(cz_app_version != null){
  297. let onlineVersion = cz_app_version.version;
  298. console.log(onlineVersion)
  299. let isForce = cz_app_version.isForce;
  300. let url = cz_app_version.down_url;
  301. self.downloadUrl = url;
  302. self.iosUrl = cz_app_version.ios_url;
  303. if(onlineVersion>appVersionCode){
  304. self.newVerson = onlineVersion;
  305. self.showStatus = true;
  306. }
  307. }
  308. });
  309. },
  310. cancelLocale(){
  311. this.showLocale = false;
  312. },
  313. setLocale(){
  314. this.locale = uni.getLocale()
  315. if(this.locale == "en"){
  316. this.localeList = [[{"label":"Chinese","id":"zh-Hans"},{"label":"English","id":"en"}]];
  317. this.localeConfig={"zh-Hans":"Chinese","en":"English"};
  318. }else if(this.locale == "zh-Hans"){
  319. this.localeList = [[{"label":"简体中文","id":"zh-Hans"},{"label":"英文","id":"en"}]];
  320. this.localeConfig={"zh-Hans":"简体中文","en":"英文"};
  321. }
  322. },
  323. changeLanguage(e){
  324. this.showLocale =false;
  325. console.log(e.value[0].id)
  326. uni.setLocale(e.value[0].id);
  327. },
  328. changeLocale(){
  329. this.showLocale = true;
  330. },
  331. buleTeeth(){
  332. this.$tab.navigateTo('/pages/bluetooth/index/index')
  333. },
  334. checkLogin(){
  335. let token = getToken()
  336. if(token){
  337. this.loginSuccess()
  338. }else{
  339. }
  340. },
  341. // // 隐私协议
  342. // handlePrivacy() {
  343. // let site = this.globalConfig.appInfo.agreements[0]
  344. // this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  345. // },
  346. // 用户协议
  347. handleUserAgrement() {
  348. let site = this.globalConfig.appInfo.agreements[1]
  349. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  350. },
  351. // // 获取图形验证码
  352. // getCode() {
  353. // getCodeImg().then(res => {
  354. // this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  355. // if (this.captchaEnabled) {
  356. // this.codeUrl = 'data:image/gif;base64,' + res.img
  357. // this.loginForm.uuid = res.uuid
  358. // }
  359. // })
  360. // },
  361. // 登录方法
  362. async handleLogin() {
  363. if(this.locale == "zh-Hans"){
  364. this.showCode = true;
  365. return;
  366. }
  367. if (this.loginForm.username === "") {
  368. this.$modal.msgError(this.$t('login.logintip'))
  369. } else if (this.loginForm.password === "") {
  370. this.$modal.msgError(this.$t('login.pwdtip'))
  371. }
  372. // else if (this.loginForm.code === "" && this.captchaEnabled) {
  373. // this.$modal.msgError("请输入验证码")}
  374. else {
  375. this.$modal.loading(this.$t('login.logining'))
  376. this.pwdLogin()
  377. }
  378. },
  379. // 密码登录
  380. async pwdLogin() {
  381. this.$store.dispatch('Login', this.loginForm).then(() => {
  382. this.$modal.closeLoading()
  383. this.loginSuccess()
  384. }).catch(() => {
  385. // if (this.captchaEnabled) {
  386. // this.getCode()
  387. // }
  388. })
  389. },
  390. // 登录成功后,处理函数
  391. loginSuccess(result) {
  392. //保存用户信息
  393. this.saveLoginInfo()
  394. // 设置用户信息
  395. this.$store.dispatch('GetInfo').then(res => {
  396. this.$tab.reLaunch('/pages/index')
  397. })
  398. },
  399. // async handleRegister() {
  400. // if (this.register.newUsername === '' || this.register.newPassword === '') {
  401. // // 如果用户名或密码为空,则弹出提示框
  402. // uni.showToast({
  403. // title: '请输入用户名和密码',
  404. // icon: 'none'
  405. // })
  406. // return
  407. // }
  408. // // 发送注册请求
  409. // uni.showLoading({
  410. // title: '注册中...'
  411. // })
  412. // uni.request({
  413. // url: 'http://localhost:8080/login/mailRegister',
  414. // method: 'POST',
  415. // data: {
  416. // username: this.register.newUsername,
  417. // password: this.register.newPassword
  418. // },
  419. // success: res => {
  420. // // uni.hideLoading()
  421. // if (res.data.success) {
  422. // // 注册成功,弹出提示框并回到登录模式
  423. // uni.showToast({
  424. // title: '注册成功',
  425. // success: () => {
  426. // this.isLogin = true
  427. // this.register.newUsername = ''
  428. // this.register.newPassword = ''
  429. // }
  430. // })
  431. // } else {
  432. // // 注册失败,弹出提示框显示错误信息
  433. // uni.showToast({
  434. // title: res.data.message || '注册成功',
  435. // icon: 'none'
  436. // })
  437. // }
  438. // },
  439. // fail: err => {
  440. // uni.hideLoading()
  441. // uni.showToast({
  442. // title: err.errMsg || '注册失败',
  443. // icon: 'none'
  444. // })
  445. // }
  446. // })
  447. // },
  448. // 注册方法
  449. async handleRegister() {
  450. // debugger
  451. if (this.register.username === "") {
  452. this.$modal.msgError(this.$t('register.logintip'))
  453. } else if (this.register.password === "") {
  454. this.$modal.msgError(this.$t('register.pwdtip'))
  455. }
  456. // else if (this.loginForm.code === "" && this.captchaEnabled) {
  457. // this.$modal.msgError("请输入验证码")}
  458. else {
  459. // debugger
  460. this.$modal.loading(this.$t('register.logining'))
  461. this.pwdRegister()
  462. }
  463. },
  464. // 用户注册
  465. async pwdRegister() {
  466. this.$store.dispatch("Register",this.register).then(res => {
  467. if (res.msg) {
  468. this.$modal.showToast(res.msg)
  469. return;
  470. }
  471. this.loginForm.username = this.register.username;
  472. this.loginForm.password = this.register.password;
  473. this.$modal.closeLoading()
  474. this.registerSuccess()
  475. });
  476. },
  477. // 注册成功后,处理函数
  478. registerSuccess(result){
  479. // 设置用户信息
  480. this.toggleLoginMode();
  481. },
  482. toggleLoginMode() {
  483. // 切换登录/注册模式
  484. this.isLogin = !this.isLogin
  485. if(this.isLogin){
  486. this.register.username = "";
  487. this.register.password = "";
  488. }
  489. }
  490. }
  491. }
  492. </script>
  493. <style lang="scss">
  494. page {
  495. background-color: #ffffff;
  496. }
  497. .normal-login-container {
  498. background-image: url('../static/images/new/starts/bg1.jpg');
  499. background-size: cover;
  500. background-repeat: no-repeat;
  501. width: 100%;
  502. height: 102.5vh;
  503. font-family: 思源黑体;
  504. margin-top: -20px;
  505. .logo-content {
  506. width: 100%;
  507. font-size: 21px;
  508. text-align: center;
  509. padding-top: 15%;
  510. .image {
  511. border-radius: 4px;
  512. }
  513. .title {
  514. width: 244px;
  515. font-weight: bold;
  516. margin-left: -56px;
  517. text-align: left;
  518. margin-top: -425px;
  519. z-index: 1;
  520. white-space: nowrap;
  521. // line-height: 51px;
  522. text-stroke: 2px #FFFFFF;
  523. font-size: 34px;
  524. // letter-spacing: 2px;
  525. color: #57B03D;
  526. text-shadow: 0 2px white, 2px 0 white, -2px 0 white, 0 -2px white;
  527. }
  528. .welcome {
  529. z-index: 2;
  530. font-size: 15px;
  531. font-family: Source Han Sans CN;
  532. font-weight: 400;
  533. color: aliceblue;
  534. }
  535. .welcome1 {
  536. margin-top: -278px;
  537. margin-left: 8px;
  538. font-family: Alibaba PuHuiTi;
  539. z-index: 2;
  540. font-size: 12px;
  541. }
  542. }
  543. .login-form-content {
  544. text-align: center;
  545. margin: -260px 20px 20px 40px;
  546. // margin-top: 15%;
  547. width: 80%;
  548. // margin-top: -200px;
  549. z-index: 1;
  550. .input-item {
  551. margin: 20px 0 20px 0;
  552. height: 45px;
  553. border-radius: 8px;
  554. background-color: #f0fdfc;
  555. border: 1px solid #e3e3e3;
  556. opacity: 0.5;
  557. color: #e3e3e3;
  558. text-indent:1em;
  559. .icon {
  560. // margin-left: 10px;
  561. font-size: 38rpx;
  562. margin-left: 0px;
  563. }
  564. .input {
  565. width: 122%;
  566. font-size: 14px;
  567. line-height: 27px;
  568. text-align: left;
  569. padding-left: 15px;
  570. color: #d8d8d8;
  571. margin-left: 10;
  572. }
  573. }
  574. .login-btn {
  575. margin-top: 30px;
  576. height: 40px;
  577. border-radius: 8px;
  578. background-color: #57B03D;
  579. }
  580. .xieyi {
  581. color: #333;
  582. margin-top: 100px;
  583. }
  584. .login-code {
  585. height: 38px;
  586. float: right;
  587. .login-code-img {
  588. height: 38px;
  589. position: absolute;
  590. margin-left: 10px;
  591. width: 200rpx;
  592. }
  593. }
  594. }
  595. .text-green {
  596. color: #57B03D;
  597. }
  598. .img {
  599. margin-top: 25px;
  600. text-align:center
  601. }
  602. .blue-text {
  603. color: #666;
  604. text-align:center
  605. }
  606. }
  607. </style>