login.vue 17 KB

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