login.vue 12 KB

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