login.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. <template>
  2. <view class="normal-login-container">
  3. <view style="position: fixed;left: 10px;z-index: 999999;top:50px;font-size: 10px;">{{i18('版本')}}:{{version}}</view>
  4. <view style="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>
  8. <image style="width: 750px;height: 807px;" :src="imgUrl+'/login/backImg2.png'" mode="widthFix"/>
  9. <view class="logo-content align-center justify-center flex">
  10. <text class="title" style="font-size: 25px;margin-left:-71px">{{$t('login.title') }}</text>
  11. </view>
  12. <view class="logo-content justify-center flex">
  13. <text class="welcome" style="">Welcome</text>
  14. </view>
  15. <view class="logo-content justify-center flex">
  16. <text class="welcome1" style=""></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="#0E9F9B"></uni-icons>
  26. </uni-col>
  27. <uni-col :span="22">
  28. <input 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" size="20" color="#0E9F9B"></uni-icons>
  37. </uni-col>
  38. <uni-col :span="22">
  39. <uni-easyinput style="margin-left:-10px ;" :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="#0E9F9B"></uni-icons>
  66. </uni-col>
  67. <uni-col :span="22">
  68. <input 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="#0E9F9B"></uni-icons>
  77. </uni-col>
  78. <uni-col :span="22">
  79. <input v-model="register.password" 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. }
  175. });
  176. this.setLocale()
  177. uni.getLocation({
  178. type: 'wgs84',
  179. success: function (res) {
  180. console.log('当前位置的经度:' + res.longitude);
  181. console.log('当前位置的纬度:' + res.latitude);
  182. }
  183. });
  184. this.checkVersion();
  185. this.checkLogin();
  186. },
  187. methods: {
  188. forgetPwd(){
  189. let self = this;
  190. uni.showModal({
  191. editable:true,
  192. title: i18('请输入邮箱'),
  193. success: function (res) {
  194. if (res.confirm) {
  195. let mail = res.content;
  196. if(!mail){
  197. uni.showToast({
  198. title: i18('邮箱不能为空'),
  199. icon: 'none'
  200. })
  201. return;
  202. }
  203. forgetPwd(mail,self.locale).then(res=>{
  204. if(res.data){
  205. uni.showToast({
  206. title: i18('请查看邮箱进行操作'),
  207. icon: 'none'
  208. })
  209. }else{
  210. uni.showToast({
  211. title: msg,
  212. icon: 'none'
  213. })
  214. }
  215. });
  216. } else if (res.cancel) {
  217. console.log('用户点击取消');
  218. }
  219. }
  220. });
  221. },
  222. closeCode(){
  223. this.showCode = false
  224. },
  225. i18(text){
  226. return i18(text)
  227. },
  228. downloadFile(){
  229. let self = this;
  230. const platform = this.platom.toLowerCase();
  231. if (platform == 'android') {
  232. let downUrl = self.downloadUrl;
  233. plus.runtime.openURL(downUrl);
  234. }else{
  235. const appleId = '86726R3L5K'; // 这里替换成你的 apple id
  236. plus.runtime.launchApplication({
  237. action: self.iosUrl
  238. },
  239. function(e) {
  240. console.log('Open system default browser failed: ' + e.message);
  241. }
  242. );
  243. }
  244. // self.isShowProgress = true;
  245. // const downloadTask = uni.downloadFile({
  246. // url: self.downloadUrl,
  247. // success: res => {
  248. // if (res.statusCode === 200) {
  249. // this.isShowProgress = false;
  250. // console.log('下载成功');
  251. // }
  252. // let that = this;
  253. // plus.runtime.install(res
  254. // .tempFilePath, {
  255. // force: false
  256. // },
  257. // function() {
  258. // plus.runtime
  259. // .restart();
  260. // });
  261. // }
  262. // })
  263. // console.log(downloadTask)
  264. // downloadTask.onProgressUpdate((res) => {
  265. // if(res.progress > 0) {
  266. // this.isShowProgress = true;
  267. // }
  268. // this.progress = res.progress;
  269. // console.log('下载进度:' + res.progress);
  270. // console.log('已下载长度:' + res.totalBytesWritten);
  271. // console.log('文件总长度:' + res.totalBytesExpectedToWrite);
  272. // })
  273. },
  274. checkVersion(){
  275. let appBaseInfo = uni.getAppBaseInfo();
  276. let appVersionCode = appBaseInfo.appVersionCode;
  277. this.appVersionCode = appVersionCode;
  278. this.version = appVersionCode;
  279. let self = this;
  280. checkVersion({"versionCode":appVersionCode}).then(res=>{
  281. let cz_app_version =res.data;
  282. console.log(cz_app_version)
  283. if(cz_app_version != null){
  284. let onlineVersion = cz_app_version.version;
  285. console.log(onlineVersion)
  286. let isForce = cz_app_version.isForce;
  287. let url = cz_app_version.down_url;
  288. self.downloadUrl = url;
  289. self.iosUrl = cz_app_version.ios_url;
  290. if(onlineVersion>appVersionCode){
  291. self.newVerson = onlineVersion;
  292. self.showStatus = true;
  293. }
  294. }
  295. });
  296. },
  297. cancelLocale(){
  298. this.showLocale = false;
  299. },
  300. setLocale(){
  301. this.locale = uni.getLocale()
  302. if(this.locale == "en"){
  303. this.localeList = [[{"label":"Chinese","id":"zh-Hans"},{"label":"English","id":"en"}]];
  304. this.localeConfig={"zh-Hans":"Chinese","en":"English"};
  305. }else if(this.locale == "zh-Hans"){
  306. this.localeList = [[{"label":"简体中文","id":"zh-Hans"},{"label":"英文","id":"en"}]];
  307. this.localeConfig={"zh-Hans":"简体中文","en":"英文"};
  308. }
  309. },
  310. changeLanguage(e){
  311. this.showLocale =false;
  312. console.log(e.value[0].id)
  313. uni.setLocale(e.value[0].id);
  314. },
  315. changeLocale(){
  316. this.showLocale = true;
  317. },
  318. buleTeeth(){
  319. this.$tab.navigateTo('/pages/bluetooth/index/index')
  320. },
  321. checkLogin(){
  322. let token = getToken()
  323. if(token){
  324. this.loginSuccess()
  325. }else{
  326. }
  327. },
  328. // // 隐私协议
  329. // handlePrivacy() {
  330. // let site = this.globalConfig.appInfo.agreements[0]
  331. // this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  332. // },
  333. // 用户协议
  334. handleUserAgrement() {
  335. let site = this.globalConfig.appInfo.agreements[1]
  336. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  337. },
  338. // // 获取图形验证码
  339. // getCode() {
  340. // getCodeImg().then(res => {
  341. // this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  342. // if (this.captchaEnabled) {
  343. // this.codeUrl = 'data:image/gif;base64,' + res.img
  344. // this.loginForm.uuid = res.uuid
  345. // }
  346. // })
  347. // },
  348. // 登录方法
  349. async handleLogin() {
  350. if(this.locale == "zh-Hans"){
  351. this.showCode = true;
  352. return;
  353. }
  354. if (this.loginForm.username === "") {
  355. this.$modal.msgError(this.$t('login.logintip'))
  356. } else if (this.loginForm.password === "") {
  357. this.$modal.msgError(this.$t('login.pwdtip'))
  358. }
  359. // else if (this.loginForm.code === "" && this.captchaEnabled) {
  360. // this.$modal.msgError("请输入验证码")}
  361. else {
  362. this.$modal.loading(this.$t('login.logining'))
  363. this.pwdLogin()
  364. }
  365. },
  366. // 密码登录
  367. async pwdLogin() {
  368. this.$store.dispatch('Login', this.loginForm).then(() => {
  369. this.$modal.closeLoading()
  370. this.loginSuccess()
  371. }).catch(() => {
  372. // if (this.captchaEnabled) {
  373. // this.getCode()
  374. // }
  375. })
  376. },
  377. // 登录成功后,处理函数
  378. loginSuccess(result) {
  379. // 设置用户信息
  380. this.$store.dispatch('GetInfo').then(res => {
  381. this.$tab.reLaunch('/pages/index')
  382. })
  383. },
  384. // async handleRegister() {
  385. // if (this.register.newUsername === '' || this.register.newPassword === '') {
  386. // // 如果用户名或密码为空,则弹出提示框
  387. // uni.showToast({
  388. // title: '请输入用户名和密码',
  389. // icon: 'none'
  390. // })
  391. // return
  392. // }
  393. // // 发送注册请求
  394. // uni.showLoading({
  395. // title: '注册中...'
  396. // })
  397. // uni.request({
  398. // url: 'http://localhost:8080/login/mailRegister',
  399. // method: 'POST',
  400. // data: {
  401. // username: this.register.newUsername,
  402. // password: this.register.newPassword
  403. // },
  404. // success: res => {
  405. // // uni.hideLoading()
  406. // if (res.data.success) {
  407. // // 注册成功,弹出提示框并回到登录模式
  408. // uni.showToast({
  409. // title: '注册成功',
  410. // success: () => {
  411. // this.isLogin = true
  412. // this.register.newUsername = ''
  413. // this.register.newPassword = ''
  414. // }
  415. // })
  416. // } else {
  417. // // 注册失败,弹出提示框显示错误信息
  418. // uni.showToast({
  419. // title: res.data.message || '注册成功',
  420. // icon: 'none'
  421. // })
  422. // }
  423. // },
  424. // fail: err => {
  425. // uni.hideLoading()
  426. // uni.showToast({
  427. // title: err.errMsg || '注册失败',
  428. // icon: 'none'
  429. // })
  430. // }
  431. // })
  432. // },
  433. // 注册方法
  434. async handleRegister() {
  435. // debugger
  436. if (this.register.username === "") {
  437. this.$modal.msgError(this.$t('register.logintip'))
  438. } else if (this.register.password === "") {
  439. this.$modal.msgError(this.$t('register.pwdtip'))
  440. }
  441. // else if (this.loginForm.code === "" && this.captchaEnabled) {
  442. // this.$modal.msgError("请输入验证码")}
  443. else {
  444. // debugger
  445. this.$modal.loading(this.$t('register.logining'))
  446. this.pwdRegister()
  447. }
  448. },
  449. // 用户注册
  450. async pwdRegister() {
  451. this.$store.dispatch("Register",this.register).then(res => {
  452. if (res.msg) {
  453. this.$modal.showToast(res.msg)
  454. return;
  455. }
  456. this.loginForm.username = this.register.username;
  457. this.loginForm.password = this.register.password;
  458. this.$modal.closeLoading()
  459. this.registerSuccess()
  460. });
  461. },
  462. // 注册成功后,处理函数
  463. registerSuccess(result){
  464. // 设置用户信息
  465. this.toggleLoginMode();
  466. },
  467. toggleLoginMode() {
  468. // 切换登录/注册模式
  469. this.isLogin = !this.isLogin
  470. if(this.isLogin){
  471. this.register.username = "";
  472. this.register.password = "";
  473. }
  474. }
  475. }
  476. }
  477. </script>
  478. <style lang="scss">
  479. page {
  480. background-color: #ffffff;
  481. }
  482. .normal-login-container {
  483. width: 100%;
  484. font-family: 思源黑体;
  485. margin-top: -20px;
  486. .logo-content {
  487. width: 100%;
  488. font-size: 21px;
  489. text-align: center;
  490. padding-top: 15%;
  491. .image {
  492. border-radius: 4px;
  493. }
  494. .title {
  495. width: 244px;
  496. font-weight: bold;
  497. margin-left: -56px;
  498. text-align: left;
  499. margin-top: -425px;
  500. z-index: 1;
  501. white-space: nowrap;
  502. // line-height: 51px;
  503. text-stroke: 2px #FFFFFF;
  504. font-size: 34px;
  505. // letter-spacing: 2px;
  506. color: #0E9F9B;
  507. text-shadow: 0 2px white, 2px 0 white, -2px 0 white, 0 -2px white;
  508. }
  509. .welcome {
  510. margin-top: -245px;
  511. margin-left: -178px;
  512. z-index: 2;
  513. font-size: 31px;
  514. font-family: Source Han Sans CN;
  515. font-weight: 400;
  516. }
  517. .welcome1 {
  518. margin-top: -278px;
  519. margin-left: 8px;
  520. font-family: Alibaba PuHuiTi;
  521. z-index: 2;
  522. font-size: 12px;
  523. }
  524. }
  525. .login-form-content {
  526. text-align: center;
  527. margin: -260px 20px 20px 40px;
  528. // margin-top: 15%;
  529. width: 80%;
  530. // margin-top: -200px;
  531. z-index: 1;
  532. .input-item {
  533. margin: 20px 0 20px 0;
  534. height: 45px;
  535. border-radius: 8px;
  536. background-color: #f0fdfc;
  537. border: 1px solid #0E9F9B;
  538. opacity: 0.5;
  539. color: #0E9F9B;
  540. text-indent:1em;
  541. .icon {
  542. // margin-left: 10px;
  543. font-size: 38rpx;
  544. margin-left: 0px;
  545. }
  546. .input {
  547. width: 122%;
  548. font-size: 14px;
  549. line-height: 27px;
  550. text-align: left;
  551. padding-left: 15px;
  552. color: #0E9F9B;
  553. margin-left: 10;
  554. }
  555. }
  556. .login-btn {
  557. margin-top: 30px;
  558. height: 40px;
  559. border-radius: 8px;
  560. background-color: #0E9F9B;
  561. }
  562. .xieyi {
  563. color: #333;
  564. margin-top: 100px;
  565. }
  566. .login-code {
  567. height: 38px;
  568. float: right;
  569. .login-code-img {
  570. height: 38px;
  571. position: absolute;
  572. margin-left: 10px;
  573. width: 200rpx;
  574. }
  575. }
  576. }
  577. .text-green {
  578. color: #0E9F9B;
  579. }
  580. .img {
  581. margin-top: 25px;
  582. text-align:center
  583. }
  584. .blue-text {
  585. color: #666;
  586. text-align:center
  587. }
  588. }
  589. </style>