login.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="container">
  3. <!-- <view class="title">登录</view> -->
  4. <input class="input-phone" placeholder="请输入手机号码" type='number' maxlength="11" :value="phone"
  5. @input="phone_input" @blur="yz_phone"/>
  6. <view style="margin-top: 20px;margin-left: 30px;width: 290px;">
  7. <input class="input-yanzhen" placeholder="请输入验证码" @input="yan_input" type='number' :value="yanzhen"/>
  8. <view class="send" @click="sendCode" v-if="disabled==false">发送验证码</view>
  9. <view class="send" style="background-color: #CCCCCC;" v-else>{{codeMsg}}</view>
  10. </view>
  11. <view class="login" @click="login">登录</view>
  12. </view>
  13. </template>
  14. <script>
  15. import until from '../../common/jiaoyan.js'
  16. import { JSEncrypt } from 'jsencrypt';
  17. export default {
  18. data() {
  19. return {
  20. phone:'',//手机号
  21. yanzhen:'',//验证码
  22. numbercode:60,//倒计时时间
  23. codeMsg:'',//倒计时验证码内容
  24. disabled:false,
  25. name:'',//同户名
  26. // RSA加密结果
  27. resultEncodeP: '',//加密手机号
  28. resultEncodeY: '',//加密验证码
  29. // RSA解密结果
  30. resultDecodeN: '',//解密
  31. resultDecodeY: '',
  32. list:[]
  33. }
  34. },
  35. onReady() {
  36. this.codeMsg = '重发('+this.numbercode+')';
  37. },
  38. onLoad() {
  39. // let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  40. // let curRoute = routes[routes.length - 1].route //获取当前页面路由
  41. let url=location.href
  42. uni.setStorageSync('url',url)
  43. },
  44. methods: {
  45. // // 加密
  46. // export function encrypt (txt: string): string {
  47. // let cryptFirst = new JSEncryptWX()
  48. // cryptFirst.setPublicKey(publicKey)
  49. // return cryptFirst.encrypt(txt) || ''
  50. // },
  51. // // 解密
  52. // export function decrypt (txt: string): string {
  53. // let cryptFirst = new JSEncryptWX()
  54. // cryptFirst.setPrivateKey(privateKey)
  55. // return cryptFirst.decrypt(txt) || ''
  56. // },
  57. //登录
  58. login(){
  59. // 开始加密
  60. this.resultEncodeP = this.$fns.rsaEncode(this.phone)
  61. console.log(this.resultEncodeP);
  62. // 开始解密
  63. this.resultDecodeY = this.$fns.rsaDecode(this.resultEncodeP)
  64. console.log(this.resultDecodeY);
  65. this.resultEncodeY = this.$fns.rsaEncode(this.yanzhen)
  66. this.$axios.post('/shareVideo/api/logInfo/logIn?phone='+this.resultEncodeP+'&code='+this.resultEncodeY,
  67. {
  68. headers:{
  69. }
  70. }).then(res => {
  71. if (res.data.success) {
  72. console.log(res.data.data)
  73. var shu=res.data.data
  74. // for(var i=0;i<shu.length;i++){
  75. // var jiemi=this.$fns.rsaDecode(shu[i])
  76. // this.resultDecodeN=jiemi
  77. // console.log(this.resultDecodeN);
  78. // }
  79. // 开始解密
  80. this.resultDecodeN = this.$fns.rsaDecode(shu[0])+
  81. this.$fns.rsaDecode(shu[1])+this.$fns.rsaDecode(shu[2])+
  82. this.$fns.rsaDecode(shu[3])+this.$fns.rsaDecode(shu[4])+
  83. this.$fns.rsaDecode(shu[5])+this.$fns.rsaDecode(shu[6])
  84. console.log(JSON.parse(this.resultDecodeN));
  85. console.log(JSON.parse(this.resultDecodeN).token)
  86. uni.setStorageSync('token',JSON.parse(this.resultDecodeN).token)
  87. uni.setStorageSync('userName',JSON.parse(this.resultDecodeN).userName)
  88. uni.setStorageSync('telPhone',JSON.parse(this.resultDecodeN).telPhone)
  89. // this.name=JSON.parse(this.resultDecodeN).userName
  90. uni.navigateTo({
  91. url:'/pages/index/index'
  92. })
  93. } else {
  94. uni.showToast({ title: res.data.message, icon: 'none' });
  95. }
  96. }).catch(res =>{
  97. });
  98. },
  99. // 输入手机号
  100. phone_input(e) {
  101. this.phone = e.detail.value;
  102. },
  103. // 验证手机号
  104. yz_phone() {
  105. if (this.phone == '') {
  106. uni.showToast({ title: '请输入手机号', icon: 'none' });
  107. return;
  108. }
  109. if (!until.checkMobile(this.phone)) {
  110. uni.showToast({ title: '手机号格式错误', icon: 'none' });
  111. return;
  112. }
  113. },
  114. //输入验证码
  115. yan_input(e){
  116. this.yanzhen=e.detail.value;
  117. },
  118. //点击验证码发送
  119. sendCode(){
  120. //验证手机号是否存在
  121. this.$axios.get('/shareVideo/api/logInfo/verify?phone='+parseInt(this.phone),
  122. ).then(res => {
  123. if (res.data.success) {
  124. this.disabled = true;
  125. let timer = setInterval(()=>{
  126. --this.numbercode;
  127. this.codeMsg = '重发('+this.numbercode+')';
  128. },1000);
  129. setTimeout(()=>{
  130. clearInterval(timer);
  131. this.numbercode=60;
  132. this.disabled = false;
  133. },60000)
  134. } else {
  135. uni.showToast({ title: '手机号无权限', icon: 'none' });
  136. }
  137. }).catch(res =>{
  138. });
  139. },
  140. }
  141. }
  142. </script>
  143. <style>
  144. .container {
  145. padding: 80px 20px 0 20px;
  146. background-image: url('../../static/login-bg.png');
  147. width: 749rpx;
  148. height: 1211rpx;
  149. background-size: 100%;
  150. font-size: 14px;
  151. line-height: 24px;
  152. }
  153. .title{
  154. font-size: 27px;
  155. text-align: center;
  156. }
  157. .input-phone{
  158. position: absolute;
  159. padding-left: 50rpx;
  160. margin-top: 264rpx;
  161. margin-left: 30px;
  162. width: 540rpx;
  163. height: 90rpx;
  164. opacity: 1;
  165. opacity: 1;
  166. border-radius: 15rpx;
  167. border: 1rpx solid rgba(128, 128, 128, 1);
  168. }
  169. .input-yanzhen{
  170. position: absolute;
  171. padding-left: 50rpx;
  172. margin-top: 354rpx;
  173. width: 180px;
  174. height: 90rpx;
  175. opacity: 1;
  176. border-radius: 15rpx;
  177. border: 1rpx solid rgba(128, 128, 128, 1);
  178. float: left;
  179. }
  180. .send{
  181. position: absolute;
  182. margin-left: 414rpx;
  183. margin-top: 354rpx;
  184. width: 175rpx;
  185. height: 90rpx;
  186. opacity: 1;
  187. border-radius: 15rpx;
  188. background: #00A0E9;
  189. font-size: 32rpx;
  190. font-weight: 400;
  191. line-height: 78rpx;
  192. color: rgba(255, 255, 255, 1);
  193. text-align: center;
  194. float: right;
  195. }
  196. .login{
  197. position: absolute;
  198. margin-left: 30rpx;
  199. margin-top: 524rpx;
  200. width: 589rpx;
  201. height: 90rpx;
  202. margin-left: 30px;
  203. opacity: 1;
  204. border-radius: 6rpx;
  205. background: #00A0E9;
  206. box-shadow: 0px -5rpx 13rpx 0px rgba(0, 0, 0, 0.25);
  207. font-size: 32rpx;
  208. font-weight: 400;
  209. line-height: 90rpx;
  210. color: rgba(255, 255, 255, 1);
  211. text-align: center;
  212. }
  213. </style>