login.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="jz_login">
  3. <view class="uni-flex login-top">
  4. <image mode="widthFix" src="../../../static/login/login_bg.png"></image>
  5. <div class="waveWrapper waveAnimation">
  6. <div class="circles">
  7. <div class="circle"></div>
  8. <div class="circle"></div>
  9. <div class="circle"></div>
  10. <div class="circle"></div>
  11. <div class="circle"></div>
  12. <div class="circle"></div>
  13. <div class="circle"></div>
  14. </div>
  15. </div>
  16. </view>
  17. <view class=" space"></view>
  18. <view class="login-box uni-column ">
  19. <view class="login-form uni-flex uni-column">
  20. <view class="logoImg uni-flex" @click="Home">
  21. <image src="../../../static/login/login_logo.png"></image>
  22. </view>
  23. <view class="tab uni-flex uni-flex-item uni-column">
  24. <view class="uni-flex uni-row login-tab">
  25. <view @click="Mode(0)" class="uni-flex uni-flex-item " v-bind:class="[current==0 ? activeClass : '']">
  26. 密码登录
  27. </view>
  28. <view @click="Mode(1)" class="uni-flex uni-flex-item " v-bind:class="[current==1 ? activeClass : '']">
  29. 短信登录
  30. </view>
  31. </view>
  32. <view class="uni-flex content uni-flex-item">
  33. <view class="uni-flex uni-column" v-show="current === 0">
  34. <view class="form-phone uni-flex">
  35. <view class="form-phone-lf uni-flex">
  36. <image src="../../../static/login/ico1.png"></image>
  37. </view>
  38. <input class="uni-flex-item userNameIput" placeholder-style="color:#e2e2e2" v-model="phone" name="input"
  39. placeholder="输入手机号码" />
  40. </view>
  41. <view class="form-phone uni-flex">
  42. <view class="form-phone-lf uni-flex">
  43. <image src="../../../static/login/ico2.png"></image>
  44. </view>
  45. <input class="uni-flex-item userNameIput" password placeholder-style="color:#e2e2e2" v-model="password" name="input"
  46. placeholder="输入登录密码" />
  47. </view>
  48. </view>
  49. <view class="uni-flex uni-column" v-show="current === 1">
  50. <view class="form-phone uni-flex">
  51. <view class="form-phone-lf uni-flex">
  52. <image src="../../../static/login/ico1.png"></image>
  53. </view>
  54. <input class="uni-flex-item userNameIput" placeholder-style="color:#e2e2e2" v-model="phone" name="input"
  55. placeholder="输入手机号码" />
  56. </view>
  57. <view class="form-phone uni-flex">
  58. <view class="form-phone-lf uni-flex">
  59. <image src="../../../static/login/login_message.png"></image>
  60. </view>
  61. <input class="uni-flex-item userNameIput" placeholder-style="color:#e2e2e2" v-model="code" name="input"
  62. placeholder="输入短信验证码" />
  63. <view class="codeBtn uni-flex" >
  64. <button class="send uni-flex-item" :type="type" size="mini" @click="SendEsms">{{content}}</button>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="btnImg" @click="Login">
  71. 登录
  72. </view>
  73. </view>
  74. <view class="login-tip uni-flex">
  75. <view class="registerMsg" @click="goRegister">注册账号</view>
  76. <view class="line"></view>
  77. <view class="registerMsg" @click="goHome">返回首页</view>
  78. </view>
  79. </view>
  80. </view>
  81. </template>
  82. <script>
  83. import {
  84. mapState,
  85. mapMutations
  86. } from 'vuex'
  87. import group from '../../../common/group.js';
  88. import sha1 from '../../../common/sha1.js';
  89. export default {
  90. computed: {
  91. ...mapState(['hasLogin', 'forcedLogin', 'jyyUser', 'favs'])
  92. },
  93. data() {
  94. return {
  95. url: "",
  96. phone: "",
  97. password: "",
  98. code: "",
  99. vcode: "",
  100. current: 0,
  101. activeClass: "login-tab-on",
  102. content: '发送验证码',
  103. totalTime: 10,
  104. type: "primary",
  105. canClick: true,
  106. };
  107. },
  108. onLoad(e) {
  109. this.url = e.url;
  110. this.init();
  111. },
  112. methods: {
  113. ...mapMutations(['login', 'setFavs', 'setShare']),
  114. goRegister() {
  115. uni.navigateTo({
  116. url: '../register/register'
  117. })
  118. },
  119. goHome(){
  120. uni.switchTab({
  121. url:'../../home/home'
  122. })
  123. },
  124. Mode(e) {
  125. this.current = e;
  126. },
  127. Home() {
  128. uni.switchTab({
  129. url: '../../home/home'
  130. })
  131. },
  132. init() {
  133. if (this.hasLogin) {
  134. uni.navigateBack({
  135. delta: 1
  136. });
  137. }
  138. },
  139. SendEsms() {
  140. if (this.phone == "") {
  141. uni.showToast({
  142. icon: "none",
  143. title: "请填写手机号码",
  144. })
  145. } else {
  146. if (!this.canClick) return //改动的是这两行代码
  147. uni.showLoading({
  148. title: "发送中"
  149. });
  150. uni.request({
  151. url: this.webUrl + 'SendEsms',
  152. method: 'POST',
  153. data: {
  154. mobile: this.phone
  155. },
  156. header: {
  157. 'content-type': 'application/x-www-form-urlencoded'
  158. },
  159. success: res => {
  160. uni.hideLoading()
  161. if (res.data.result.status == "1") {
  162. this.vcode = res.data.result.code;
  163. this.canClick = false
  164. this.type = "default";
  165. this.content = this.totalTime + 's'
  166. let clock = setInterval(() => {
  167. this.totalTime--
  168. this.content = this.totalTime + 's'
  169. if (this.totalTime < 0) {
  170. clearInterval(clock)
  171. this.content = '重新发送'
  172. this.totalTime = 10
  173. this.canClick = true //这里重新开启
  174. this.type = "primary"
  175. }
  176. }, 1000)
  177. } else {
  178. uni.showToast({
  179. icon: "none",
  180. title: "发送失败",
  181. })
  182. }
  183. },
  184. fail: () => {},
  185. complete: () => {}
  186. });
  187. }
  188. },
  189. Login() {
  190. if (this.phone == "") {
  191. uni.showToast({
  192. icon: "none",
  193. title: "请填写手机号",
  194. });
  195. return false;
  196. }
  197. if (this.current == 0) {
  198. if (this.password == "") {
  199. uni.showToast({
  200. icon: "none",
  201. title: "请填写登录密码",
  202. });
  203. return false;
  204. }
  205. } else {
  206. if (this.code == "") {
  207. uni.showToast({
  208. icon: "none",
  209. title: "请填写验证码",
  210. });
  211. return false;
  212. }
  213. }
  214. uni.showLoading({
  215. title: "登录中"
  216. });
  217. uni.request({
  218. url: this.webUrl + 'login',
  219. method: 'POST',
  220. data: {
  221. code: this.code,
  222. vcode: this.vcode,
  223. phone: this.phone,
  224. current: this.current,
  225. password: sha1.hex_sha1(this.password)
  226. },
  227. header: {
  228. 'content-type': 'application/x-www-form-urlencoded'
  229. },
  230. success: res => {
  231. uni.hideLoading();
  232. if (res.data.result.isSuccess) {
  233. this.login(JSON.stringify(res.data.user));
  234. this.setFavs(JSON.stringify(res.data.favs));
  235. uni.navigateBack({
  236. delta: 1
  237. });
  238. } else {
  239. uni.showToast({
  240. title: res.data.result.resultInfo,
  241. icon: "none"
  242. })
  243. }
  244. },
  245. fail: () => {},
  246. complete: () => {}
  247. });
  248. }
  249. /* wxGetUserInfo(e) {
  250. this.loading = true;
  251. if (e.detail.errMsg !== 'getUserInfo:ok') {
  252. uni.showModal({
  253. title: "获取用户信息失败",
  254. content: "错误原因" + e.detail.errMsg,
  255. showCancel: false
  256. });
  257. return;
  258. } else {
  259. uni.request({
  260. url: this.webUrl + 'Register',
  261. method: 'POST',
  262. data: {
  263. code: this.code,
  264. userInfo: JSON.stringify(e.detail.userInfo),
  265. shareId: this.shareId
  266. },
  267. header: {
  268. 'content-type': 'application/x-www-form-urlencoded'
  269. },
  270. success: res => {
  271. if (res.data.result.isSuccess) {
  272. this.loading = false;
  273. this.login(JSON.stringify(res.data.result.resultInfo));
  274. this.setFavs(JSON.stringify(res.data.result.resultInfo2));
  275. group.updateCart([]);
  276. uni.navigateBack({
  277. delta: 1
  278. });
  279. }
  280. },
  281. fail: () => {},
  282. complete: () => {}
  283. });
  284. }
  285. } */
  286. }
  287. }
  288. </script>
  289. <style>
  290. page {
  291. background: #FFFFFF;
  292. }
  293. .jz_login .btnImg {
  294. width: 460upx;
  295. text-align: center;
  296. height: 80upx;
  297. line-height: 80upx;
  298. color: #FFFFFF;
  299. background: url(../../../static/btn.png) no-repeat;
  300. background-size: 460upx 80upx;
  301. }
  302. </style>