login.vue 14 KB

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