login.vue 16 KB

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