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