login.vue 19 KB

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