login.vue 18 KB

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