login.vue 17 KB

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