login.vue 12 KB

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