login.vue 12 KB

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