login.vue 12 KB

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