login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <view class="normal-login-container">
  3. <view>
  4. <image style="width: 750px;height: 807px;" :src="imgUrl+'/login/backImg2.png'" mode="widthFix">
  5. <view class="logo-content align-center justify-center flex">
  6. <text class="title" style="">微天地充电平台</text>
  7. </view>
  8. <view class="logo-content justify-center flex">
  9. <text class="welcome" style="">欢迎登录</text>
  10. </view>
  11. <view class="logo-content justify-center flex">
  12. <text class="welcome1" style="">Welcome</text>
  13. </view>
  14. </view>
  15. <!-- 登录表单 -->
  16. <view class="login-form-content" style="z-index: 99;position: relative;" v-show="isLogin">
  17. <view class="input-item flex align-center">
  18. <!-- <view class="iconfont icon-user icon"></view> -->
  19. <uni-row>
  20. <uni-col :span="2">
  21. <uni-icons class="icon" type="email" size="20" color="#0E9F9B"></uni-icons>
  22. </uni-col>
  23. <uni-col :span="22">
  24. <input v-model="loginForm.username" class="input" type="text" :placeholder="$t('login.mailInput')" maxlength="30" />
  25. </uni-col>
  26. </uni-row>
  27. </view>
  28. <view class="input-item flex align-center">
  29. <!-- <view class="iconfont icon-password icon"></view> -->
  30. <uni-row>
  31. <uni-col :span="2">
  32. <uni-icons class="icon" type="locked" size="20" color="#0E9F9B"></uni-icons>
  33. </uni-col>
  34. <uni-col :span="22">
  35. <uni-easyinput style="margin-left:-10px ;" :inputBorder="false" v-model="loginForm.password" type="password" class="input" :placeholder="$t('login.pwdInput')" maxlength="30" />
  36. </uni-col>
  37. </uni-row>
  38. </view>
  39. <view class="xieyi text-center" style="margin-top: -10px;">
  40. <text class="text-grey">{{ $t('login.noAccount') }},</text>
  41. <text @click="toggleLoginMode" class="text-green">{{ $t('login.resiger') }}</text>
  42. <!-- <text @click="handleUserAgrement" class="text-green">立即注册</text> -->
  43. <!-- <text @click="handlePrivacy" class="text-blue">《隐私协议》</text> -->
  44. </view>
  45. <!-- <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
  46. <view class="iconfont icon-code icon"></view>
  47. <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  48. <view class="login-code"> <image :src="codeUrl" @click="getCode" class="login-code-img"></image></view >
  49. </view> -->
  50. <view class="action-btn" style="z-index: 99;position: relative;">
  51. <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">{{ $t('login.tologin') }}</button>
  52. </view>
  53. </view>
  54. <view class="login-form-content" style="z-index: 9999;position: relative;" v-show="!isLogin" @submit.prevent="handleRegister">
  55. <!-- 注册表单 -->
  56. <view>
  57. <view class="input-item flex align-center">
  58. <uni-row>
  59. <uni-col :span="2">
  60. <uni-icons class="icon" type="email" size="20" color="#0E9F9B"></uni-icons>
  61. </uni-col>
  62. <uni-col :span="22">
  63. <input v-model="register.username" class="input" type="text" placeholder="请输入新账号" maxlength="30" />
  64. </uni-col>
  65. </uni-row>
  66. </view>
  67. <view>
  68. <view class="input-item flex align-center">
  69. <uni-row>
  70. <uni-col :span="2">
  71. <uni-icons class="icon" type="locked" size="20" color="#0E9F9B"></uni-icons>
  72. </uni-col>
  73. <uni-col :span="22">
  74. <input v-model="register.password" class="input" type="text" placeholder="请输入新密码" maxlength="30" />
  75. </uni-col>
  76. </uni-row>
  77. </view>
  78. </view>
  79. <view class="xieyi text-center" style="margin-top: -10px;">
  80. <p class="text-grey">已有账号?<a href="#" @click="toggleLoginMode" class="text-green">返回登录</a></p>
  81. </view>
  82. <view class="action-btn" style="z-index: 9999;position: relative;">
  83. <button @click="handleRegister" type="submit" class="login-btn cu-btn block bg-blue lg round">注册</button>
  84. </view>
  85. </view>
  86. </view>
  87. <view v-show="isLogin">
  88. <view class="img">
  89. <image @click="buleTeeth" style="width: 31px;" :src="imgUrl+'/login/blueTeeth.png'" mode="widthFix"/>
  90. </view>
  91. <view class="blue-text">
  92. <text @click="buleTeeth">{{ $t('login.buletooth') }}</text>
  93. </view>
  94. </view>
  95. </view>
  96. </template>
  97. <script>
  98. import getCodeImg from '@/api/login'
  99. import {getToken} from "@/utils/auth";
  100. export default {
  101. data() {
  102. return {
  103. // currentImg: "",
  104. codeUrl: "",
  105. captchaEnabled: true,
  106. globalConfig: getApp().globalData.config,
  107. loginForm: {
  108. username: "",
  109. password: "",
  110. code: "",
  111. uuid: ''
  112. },
  113. register:{
  114. username: "",
  115. password: "",
  116. },
  117. isLogin: true, // 是否为登录模式
  118. }
  119. },
  120. // mounted() {
  121. // this.addTextEvent()
  122. // },
  123. computed: {
  124. imgUrl: function () {
  125. return getApp().globalData.config.imgUrl;
  126. }
  127. },
  128. created() {
  129. console.log(uni.getLocale())
  130. console.log(this.$t('locale.auto'))
  131. uni.getLocation({
  132. type: 'wgs84',
  133. success: function (res) {
  134. console.log('当前位置的经度:' + res.longitude);
  135. console.log('当前位置的纬度:' + res.latitude);
  136. }
  137. });
  138. this.checkLogin();
  139. },
  140. methods: {
  141. buleTeeth(){
  142. this.$tab.reLaunch('/pages/bluetooth/index/index')
  143. },
  144. checkLogin(){
  145. let token = getToken()
  146. if(token){
  147. this.loginSuccess()
  148. }else{
  149. }
  150. },
  151. // // 隐私协议
  152. // handlePrivacy() {
  153. // let site = this.globalConfig.appInfo.agreements[0]
  154. // this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  155. // },
  156. // 用户协议
  157. handleUserAgrement() {
  158. let site = this.globalConfig.appInfo.agreements[1]
  159. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  160. },
  161. // // 获取图形验证码
  162. // getCode() {
  163. // getCodeImg().then(res => {
  164. // this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  165. // if (this.captchaEnabled) {
  166. // this.codeUrl = 'data:image/gif;base64,' + res.img
  167. // this.loginForm.uuid = res.uuid
  168. // }
  169. // })
  170. // },
  171. // 登录方法
  172. async handleLogin() {
  173. if (this.loginForm.username === "") {
  174. this.$modal.msgError(this.$t('login.logintip'))
  175. } else if (this.loginForm.password === "") {
  176. this.$modal.msgError(this.$t('login.pwdtip'))
  177. }
  178. // else if (this.loginForm.code === "" && this.captchaEnabled) {
  179. // this.$modal.msgError("请输入验证码")}
  180. else {
  181. this.$modal.loading(this.$t('login.logining'))
  182. this.pwdLogin()
  183. }
  184. },
  185. // 密码登录
  186. async pwdLogin() {
  187. this.$store.dispatch('Login', this.loginForm).then(() => {
  188. this.$modal.closeLoading()
  189. this.loginSuccess()
  190. }).catch(() => {
  191. if (this.captchaEnabled) {
  192. this.getCode()
  193. }
  194. })
  195. },
  196. // 登录成功后,处理函数
  197. loginSuccess(result) {
  198. // 设置用户信息
  199. this.$store.dispatch('GetInfo').then(res => {
  200. this.$tab.reLaunch('/pages/index')
  201. })
  202. },
  203. // async handleRegister() {
  204. // if (this.register.newUsername === '' || this.register.newPassword === '') {
  205. // // 如果用户名或密码为空,则弹出提示框
  206. // uni.showToast({
  207. // title: '请输入用户名和密码',
  208. // icon: 'none'
  209. // })
  210. // return
  211. // }
  212. // // 发送注册请求
  213. // uni.showLoading({
  214. // title: '注册中...'
  215. // })
  216. // uni.request({
  217. // url: 'http://localhost:8080/login/mailRegister',
  218. // method: 'POST',
  219. // data: {
  220. // username: this.register.newUsername,
  221. // password: this.register.newPassword
  222. // },
  223. // success: res => {
  224. // // uni.hideLoading()
  225. // if (res.data.success) {
  226. // // 注册成功,弹出提示框并回到登录模式
  227. // uni.showToast({
  228. // title: '注册成功',
  229. // success: () => {
  230. // this.isLogin = true
  231. // this.register.newUsername = ''
  232. // this.register.newPassword = ''
  233. // }
  234. // })
  235. // } else {
  236. // // 注册失败,弹出提示框显示错误信息
  237. // uni.showToast({
  238. // title: res.data.message || '注册成功',
  239. // icon: 'none'
  240. // })
  241. // }
  242. // },
  243. // fail: err => {
  244. // uni.hideLoading()
  245. // uni.showToast({
  246. // title: err.errMsg || '注册失败',
  247. // icon: 'none'
  248. // })
  249. // }
  250. // })
  251. // },
  252. // 注册方法
  253. async handleRegister() {
  254. // debugger
  255. if (this.register.username === "") {
  256. this.$modal.msgError(this.$t('register.logintip'))
  257. } else if (this.register.password === "") {
  258. this.$modal.msgError(this.$t('register.pwdtip'))
  259. }
  260. // else if (this.loginForm.code === "" && this.captchaEnabled) {
  261. // this.$modal.msgError("请输入验证码")}
  262. else {
  263. // debugger
  264. this.$modal.loading(this.$t('register.logining'))
  265. this.pwdRegister()
  266. }
  267. },
  268. // 用户注册
  269. async pwdRegister() {
  270. this.$store.dispatch("Register",this.register).then(res => {
  271. if (res.msg) {
  272. this.$modal.showToast(res.msg)
  273. return;
  274. }
  275. this.loginForm.username = this.register.username;
  276. this.loginForm.password = this.register.password;
  277. this.$modal.closeLoading()
  278. this.registerSuccess()
  279. });
  280. },
  281. // 注册成功后,处理函数
  282. registerSuccess(result){
  283. // 设置用户信息
  284. this.toggleLoginMode();
  285. },
  286. toggleLoginMode() {
  287. // 切换登录/注册模式
  288. this.isLogin = !this.isLogin
  289. if(this.isLogin){
  290. this.register.username = "";
  291. this.register.password = "";
  292. }
  293. }
  294. }
  295. }
  296. </script>
  297. <style lang="scss">
  298. page {
  299. background-color: #ffffff;
  300. }
  301. .normal-login-container {
  302. width: 100%;
  303. font-family: 思源黑体;
  304. margin-top: -20px;
  305. .logo-content {
  306. width: 100%;
  307. font-size: 21px;
  308. text-align: center;
  309. padding-top: 15%;
  310. .image {
  311. border-radius: 4px;
  312. }
  313. .title {
  314. width: 244px;
  315. font-weight: bold;
  316. margin-left: -56px;
  317. text-align: left;
  318. margin-top: -425px;
  319. z-index: 1;
  320. white-space: nowrap;
  321. // line-height: 51px;
  322. text-stroke: 2px #FFFFFF;
  323. font-size: 34px;
  324. // letter-spacing: 2px;
  325. color: #0E9F9B;
  326. text-shadow: 0 2px white, 2px 0 white, -2px 0 white, 0 -2px white;
  327. }
  328. .welcome {
  329. margin-top: -245px;
  330. margin-left: -178px;
  331. z-index: 2;
  332. font-size: 31px;
  333. font-family: Source Han Sans CN;
  334. font-weight: 400;
  335. }
  336. .welcome1 {
  337. margin-top: -278px;
  338. margin-left: 8px;
  339. font-family: Alibaba PuHuiTi;
  340. z-index: 2;
  341. font-size: 12px;
  342. }
  343. }
  344. .login-form-content {
  345. text-align: center;
  346. margin: -260px 20px 20px 40px;
  347. // margin-top: 15%;
  348. width: 80%;
  349. // margin-top: -200px;
  350. z-index: 1;
  351. .input-item {
  352. margin: 20px 0 20px 0;
  353. height: 45px;
  354. border-radius: 8px;
  355. background-color: #f0fdfc;
  356. border: 1px solid #0E9F9B;
  357. opacity: 0.5;
  358. color: #0E9F9B;
  359. text-indent:1em;
  360. .icon {
  361. // margin-left: 10px;
  362. font-size: 38rpx;
  363. margin-left: 0px;
  364. }
  365. .input {
  366. width: 122%;
  367. font-size: 14px;
  368. line-height: 27px;
  369. text-align: left;
  370. padding-left: 15px;
  371. color: #0E9F9B;
  372. margin-left: 10;
  373. }
  374. }
  375. .login-btn {
  376. margin-top: 30px;
  377. height: 40px;
  378. border-radius: 8px;
  379. background-color: #0E9F9B;
  380. }
  381. .xieyi {
  382. color: #333;
  383. margin-top: 100px;
  384. }
  385. .login-code {
  386. height: 38px;
  387. float: right;
  388. .login-code-img {
  389. height: 38px;
  390. position: absolute;
  391. margin-left: 10px;
  392. width: 200rpx;
  393. }
  394. }
  395. }
  396. .text-green {
  397. color: #0E9F9B;
  398. }
  399. .img {
  400. margin-top: 25px;
  401. text-align:center
  402. }
  403. .blue-text {
  404. color: #666;
  405. text-align:center
  406. }
  407. }
  408. </style>