appLogin.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <view class="page">
  3. <view class="title">
  4. 登录
  5. </view>
  6. <view class="tab">
  7. <view :class="[tab === 0 ?'active' :'', 'item']" @click="tab = 0">
  8. 密码登录
  9. </view>
  10. <view :class="[tab === 1 ?'active' :'', 'item']" @click="tab = 1">
  11. 验证码登录
  12. </view>
  13. </view>
  14. <view class="input-box">
  15. <input type="number" maxlength="11" class="input" v-model="phone" placeholder="请输入手机号码">
  16. </view>
  17. <view class="input-box" v-if='tab === 0'>
  18. <input type="password" v-model="password" class="input" placeholder="请输入登录密码">
  19. </view>
  20. <view class="input-box" v-if='tab === 1'>
  21. <input type="text" v-model="code" style="width: 400rpx;" class="input" placeholder="请输入验证码">
  22. <view class="vcode" @click="getVcode" v-if="countdown <= 0">
  23. 获取验证码
  24. </view>
  25. <view class="vcode" v-else>
  26. {{countdown}}
  27. </view>
  28. </view>
  29. <view class="submit" @click="login">
  30. 登录
  31. </view>
  32. <view class="b-btn">
  33. <navigator url="./updatePwd">
  34. <view class="l">
  35. 忘记密码?
  36. </view>
  37. </navigator>
  38. <navigator url="./sigUp">
  39. <view class="r">
  40. 快速注册
  41. </view>
  42. </navigator>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. tab: 0,
  51. password: '',
  52. phone: '',
  53. code: '',
  54. key: '',
  55. countdown:0
  56. }
  57. },
  58. methods: {
  59. login() {
  60. let tip = ''
  61. if (!this.phone) {
  62. tip = '请输入手机号码'
  63. } else if (!this.password && this.tab === 0) {
  64. tip = '请输入登录密码'
  65. } else if (!this.code && this.tab === 1) {
  66. tip = '请输入验证码'
  67. }
  68. if (tip) {
  69. uni.showToast({
  70. title: tip,
  71. icon: "none"
  72. })
  73. return
  74. }
  75. this.$post({
  76. data:{
  77. do:'AppLogin',
  78. data:{
  79. phone:this.phone,
  80. password:this.tab == 0?this.password:'',
  81. code:this.tab == 0?'':this.code
  82. }
  83. }
  84. }).then(res=>{
  85. console.log(res,'++++++++')
  86. for(let i in res.data){
  87. uni.setStorageSync(i,res.data[i])
  88. }
  89. uni.showToast({
  90. title:res.message,
  91. mask:true
  92. })
  93. this.$post({
  94. data: {
  95. do: 'Vip',
  96. data: {
  97. user_id: user_id,
  98. pw: '375'
  99. }
  100. }
  101. }).then(res => {
  102. if (res.data.is_vip == 1) {
  103. uni.setStorageSync('is_vip', 1);
  104. }
  105. })
  106. setTimeout(()=>{
  107. uni.reLaunch({
  108. url:'/pages/index/index'
  109. })
  110. },1500)
  111. })
  112. return
  113. let t = this
  114. if (this.tab === 0) {
  115. t.$req({
  116. url: "authorizations",
  117. method: "POST",
  118. data: {
  119. username: this.phone,
  120. password: this.pwd
  121. }
  122. }).then(res => {
  123. console.log(res);
  124. if (!!res.code) {
  125. if (res.code === 40001) {
  126. uni.navigateTo({
  127. url: '../../pages/login/login'
  128. })
  129. } else if (res.code === 40002) {
  130. uni.showToast({
  131. title: res.message,
  132. icon: "none",
  133. duration: 5000
  134. })
  135. }
  136. } else {
  137. console.log(res.access_token);
  138. uni.setStorageSync("token", res.access_token)
  139. uni.switchTab({
  140. url: '../../pages/index/index'
  141. })
  142. }
  143. })
  144. }else{
  145. t.$req({
  146. url: "authorizations/sms",
  147. method: "POST",
  148. data: {
  149. username:this.phone,
  150. verification_key:this.key,
  151. verification_code:this.vcode,
  152. }
  153. }).then(res => {
  154. console.log(res);
  155. if (!!res.code) {
  156. if (res.code === 40001) {
  157. uni.navigateTo({
  158. url: '../../pages/login/login'
  159. })
  160. } else if (res.code === 40002) {
  161. uni.showToast({
  162. title: res.message,
  163. icon: "none",
  164. duration: 5000
  165. })
  166. }
  167. } else {
  168. uni.setStorageSync("token", res.access_token)
  169. uni.switchTab({
  170. url: '../../pages/index/index',
  171. fail(e) {
  172. console.log(e)
  173. }
  174. })
  175. }
  176. })
  177. }
  178. },
  179. getVcode() {
  180. if (!this.phone) {
  181. uni.showToast({
  182. title: '请输入手机号',
  183. icon: "none",
  184. })
  185. return
  186. }
  187. this.$post({
  188. data:{
  189. do:'GetPhoneCode',
  190. data:{
  191. phone:this.phone
  192. }
  193. }
  194. }).then(res=>{
  195. console.log(res,'++++++++')
  196. if(res.errno==2004){
  197. uni.showToast({
  198. title: '短信已发送',
  199. icon: "none",
  200. duration: 5000
  201. })
  202. this.key = res.key;
  203. if (this.countdown <= 0) {
  204. this.countdown = 60
  205. let timer = setInterval(() => {
  206. this.countdown--;
  207. if (this.countdown < 1) {
  208. clearInterval(timer);
  209. this.countdown = 0
  210. }
  211. }, 1000)
  212. }
  213. }
  214. })
  215. }
  216. }
  217. }
  218. </script>
  219. <style lang="less" scoped>
  220. .page {
  221. padding: 0 32rpx;
  222. width: 100vw;
  223. box-sizing: border-box;
  224. }
  225. .vcode {
  226. width: 180rpx;
  227. height: 70rpx;
  228. border-radius: 4rpx;
  229. border: 2rpx solid #57BD37;
  230. text-align: center;
  231. line-height: 70rpx;
  232. font-size: 32rpx;
  233. color: #57BD37;
  234. position: absolute;
  235. right: 0;
  236. bottom: 14rpx;
  237. }
  238. .title {
  239. width: 104rpx;
  240. height: 72rpx;
  241. font-size: 52rpx;
  242. font-family: PingFang SC-Bold, PingFang SC;
  243. font-weight: bold;
  244. color: #333333;
  245. padding-top: 20vh;
  246. margin-bottom: 104rpx;
  247. }
  248. .tab {
  249. display: flex;
  250. align-items: center;
  251. margin-bottom: 114rpx;
  252. .item {
  253. height: 50rpx;
  254. margin-right: 86rpx;
  255. font-size: 36rpx;
  256. font-family: PingFang SC-Medium, PingFang SC;
  257. font-weight: 500;
  258. color: #333333;
  259. &.active {
  260. color: #57BD37;
  261. position: relative;
  262. &:after {
  263. display: block;
  264. position: absolute;
  265. content: '';
  266. left: 50%;
  267. transform: translateX(-50%);
  268. width: 56rpx;
  269. height: 6rpx;
  270. background-color: #57BD37;
  271. bottom: -10rpx;
  272. }
  273. }
  274. }
  275. }
  276. .input-box {
  277. padding-bottom: 26rpx;
  278. border-bottom: 2rpx solid #E4E4E4;
  279. height: 42rpx;
  280. font-size: 30rpx;
  281. font-family: PingFang SC-Regular, PingFang SC;
  282. font-weight: 400;
  283. margin-bottom: 88rpx;
  284. width: 100%;
  285. position: relative;
  286. }
  287. .submit {
  288. width: 100%;
  289. height: 88rpx;
  290. background: linear-gradient(180deg, #6AD449 0%, #4EB32F 100%);
  291. border-radius: 40rpx;
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. font-size: 36rpx;
  296. font-family: PingFang SC-Medium, PingFang SC;
  297. font-weight: 500;
  298. color: #FFFFFF;
  299. margin-bottom: 40rpx;
  300. margin-top: 150rpx;
  301. }
  302. .b-btn {
  303. display: flex;
  304. width: 100%;
  305. justify-content: space-between;
  306. height: 44rpx;
  307. font-size: 32rpx;
  308. font-family: PingFang SC-Medium, PingFang SC;
  309. font-weight: 500;
  310. color: #666666;
  311. line-height: 44rpx;
  312. .r {
  313. color: #57BD37;
  314. }
  315. }
  316. </style>