login.vue 16 KB

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