login.vue 14 KB

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