login.vue 17 KB

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