login.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <view class="login" >
  3. <image :src="bgimg" class="loginbg"></image>
  4. <view :style="'padding-top:'+padtop+'px'">
  5. <navbar :back="false" :bgcolor="backgroundColor" fixed zIndex="1010" :center="true" :custom='true' @getTop="getTop" />
  6. <view class="login_tit">
  7. <view class="login_tita">登录</view>
  8. <view class="login_txt">欢迎使用潜商服务卡~</view>
  9. </view>
  10. <view style="padding-bottom: 56rpx;">
  11. <view class="login_i">
  12. <image :src="zimg"></image>
  13. <input placeholder="请输入账号" v-model="formData.username"/>
  14. </view>
  15. <view class="login_i">
  16. <image :src="mimg" style="width: 30rpx;height: 38rpx;margin-right: 26rpx;"></image>
  17. <input placeholder="请输入密码" type="password" v-model="formData.password"/>
  18. </view>
  19. </view>
  20. <view class="login_btn btn1" @click="passwordlogin">账号登录</view>
  21. <button type="primary" class="login_btn btn2" open-type="getUserInfo" @getuserinfo="getuserinfo">
  22. <text class="btn-txt">快速登录</text>
  23. </button>
  24. <!-- 显示弹窗 -->
  25. <div class="box_hei" @click="btn" v-if="box_status">
  26. <div @click.stop="btns" class="hei_box">
  27. <div class="box_top">
  28. <div class="box_title">
  29. <div>
  30. 潜山信惠 申请使用
  31. </div>
  32. </div>
  33. <div class="box_nameq">你的手机号码</div>
  34. </div>
  35. <!-- <div class="boxs"></div> -->
  36. <div class="box_btns">
  37. <div @click="btn" class="box_btn box_btn1">拒绝</div>
  38. <button class="box_btn box_btn2" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">允许</button>
  39. </div>
  40. </div>
  41. </div>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default{
  47. data(){
  48. return{
  49. padtop:this.$http._GET.customBarH||0,
  50. backgroundColor:'transparent',
  51. zimg:require("@/static/image/loginz.png"),
  52. mimg:require("@/static/image/loginm.png"),
  53. bgimg:require("@/static/image/lbg.png"),
  54. formData: {
  55. username: '',
  56. password: ''
  57. },
  58. box_status: false,
  59. userId:''
  60. }
  61. },
  62. onLoad() {
  63. uni.clearStorage()
  64. },
  65. methods:{
  66. getTop(e){
  67. this.padtop=e
  68. },
  69. btns() {
  70. },
  71. btn() {
  72. this.box_status = false
  73. },
  74. // 手机号登录
  75. passwordlogin() {
  76. if(!this.formData.username){
  77. uni.showToast({
  78. title: "请输入账号",
  79. duration: 1000,
  80. icon: 'none'
  81. });
  82. return
  83. }
  84. if(!this.formData.password){
  85. uni.showToast({
  86. title: "请输入密码",
  87. duration: 1000,
  88. icon: 'none'
  89. });
  90. return
  91. }
  92. // this.$http.post('boman-auth/login', this.formData).then(res=>{
  93. this.$http.post('loginApp', this.formData).then(res=>{
  94. if(res.code == 200 ) {
  95. this.userId=res.userId;
  96. uni.setStorageSync('token', res.token)
  97. uni.setStorageSync('userId', res.userId)
  98. uni.setStorageSync('businessId',res.settledMerchants.businessId)
  99. uni.setStorageSync('phone', res.settledMerchants.businessPhone)
  100. setTimeout(function(){
  101. uni.switchTab({
  102. url: '/pages/index/index',
  103. });
  104. },1000)
  105. // this.getUserInfoes();
  106. // uni.switchTab({
  107. // url: '/pages/index/index',
  108. // });
  109. } else{
  110. uni.showToast({
  111. title: res.msg,
  112. duration: 1000,
  113. icon: 'none'
  114. });
  115. }
  116. })
  117. },
  118. // 快捷登录
  119. async getPhoneNumber(e){
  120. console.log(e)
  121. const {iv,encryptedData} = e.detail
  122. console.log(iv,encryptedData)
  123. let res = await this.$http.uniApi({events: uni.login})
  124. if(res.code) {
  125. // console.log(res,9876)
  126. this.$http.post("applet/login",{
  127. iv: iv,
  128. encryptedData: encryptedData,
  129. code : res.code,
  130. // mode:this.mode,
  131. // userInfo:this.userInfo
  132. }).then(red => {
  133. // console.log(red)
  134. if(red.code == 200){
  135. // console.log(JSON.parse(red.data).phoneNumber,9999)
  136. this.box_status = false;
  137. this.userId=red.data.userId;
  138. uni.setStorageSync('token', red.data.access_token)
  139. uni.setStorageSync('userId', red.data.userId)
  140. uni.setStorageSync('businessId',red.data.settledMerchants.businessId)
  141. uni.setStorageSync('phone', red.data.settledMerchants.businessPhone)
  142. // this.getUserInfoes();
  143. uni.switchTab({
  144. url: '/pages/index/index',
  145. });
  146. // uni.navigateTo({
  147. // url: '/pages/index/index'
  148. // })
  149. }else{
  150. uni.showToast({
  151. title: red.msg,
  152. duration: 1000,
  153. icon: 'none'
  154. });
  155. }
  156. })
  157. }
  158. },
  159. // 个人信息
  160. getUserInfoes() {
  161. this.$http.get('system/user/'+this.userId).then(res=>{
  162. // console.log(JSON.stringify(res))
  163. if(res.code == 200 ) {
  164. uni.setStorageSync('phone', res.data.phonenumber)
  165. setTimeout(function(){
  166. uni.switchTab({
  167. url: '/pages/index/index',
  168. });
  169. },1000)
  170. }
  171. })
  172. },
  173. async getuserinfo(e) {
  174. console.log(e,9999)
  175. const {nickName, avatarUrl, ...userInfo} = e.detail.userInfo
  176. // uni.navigateTo({
  177. // url: `login_phone?nickName=${nickName}&avatarUrl=${avatarUrl}`
  178. // })
  179. try{
  180. let res = await this.$http.uniApi({events: uni.login})
  181. if(res.code) {
  182. // console.log(res)
  183. // console.log(res.code)
  184. // console.log(nickName)
  185. // console.log(avatarUrl)
  186. this.avatarUrl = avatarUrl
  187. this.nickName = nickName
  188. this.code = res.code
  189. this.userInfo =e.detail.userInfo
  190. uni.setStorageSync('userInfo', e.detail.userInfo)
  191. // this.bindUserinfo({code: res.code, nickName, avatarUrl})
  192. this.box_status=true
  193. }
  194. } catch(e){
  195. //TODO handle the exception
  196. }
  197. },
  198. }
  199. }
  200. </script>
  201. <style scoped lang="scss">
  202. .loginbg{width: 342rpx;height: 382rpx;position: absolute;right: 0;top: 0;z-index: -1;}
  203. .login{height: 100vh; width: 100%;box-sizing: border-box;padding: 0 74rpx;position: relative;}
  204. .login_tit{padding-top: 100rpx;margin-bottom: 150rpx;
  205. .login_tita{font-size: 48rpx;font-weight: bold;color: #2F2F2F;}
  206. .login_txt{font-size: 30rpx;color: #666666;font-weight: 400;margin-top: 12rpx;}
  207. }
  208. .login_i{
  209. display: flex;align-items: center;height:90rpx;padding: 0 32rpx;border-radius: 48rpx;margin-bottom: 28rpx;background: rgba(244, 244, 244, .6);
  210. image{
  211. width: 36rpx;height: 34rpx;margin-right: 20rpx;
  212. }
  213. input{
  214. font-size: 28rpx;color: #000000;
  215. }
  216. }
  217. .login_btn{width: 100%;height: 90rpx;display: flex;align-items: center;justify-content: center;font-size: 30rpx;border-radius: 48rpx;
  218. &.btn1{background: #A04CFF;color: #ffffff;margin-bottom: 28rpx;}
  219. &.btn2{border: 1px solid #A04CFF;color: #A04CFF;background: #fff;}
  220. }
  221. // 快捷登录弹窗
  222. .box_hei{
  223. width: 100%;
  224. height: 100%;
  225. background: rgba(0,0,0,.8);
  226. position: fixed;
  227. top: 0;
  228. left: 0;
  229. z-index: 3;
  230. .hei_box{
  231. background: #fff;
  232. border-radius:22upx 22upx 0 0;
  233. height: 440upx;
  234. padding: 52upx 28upx 104upx;
  235. position: absolute;
  236. bottom:0;
  237. width: 100%;
  238. box-sizing: border-box;
  239. .box_top{
  240. padding: 0 18upx 62upx;
  241. .box_title{
  242. display: flex;
  243. justify-content: space-between;
  244. font-size: 30upx;
  245. margin-bottom: 30upx;
  246. div{
  247. display: flex;
  248. align-items: center;
  249. color: #333333;
  250. }
  251. .img{
  252. margin-right: 14upx;
  253. width: 180upx;
  254. height: 48upx;
  255. }
  256. .imgs{
  257. width: 40upx;
  258. height: 40upx;
  259. }
  260. }
  261. .box_nameq{
  262. color: #333333;
  263. font-size: 44upx;
  264. font-weight: bold;
  265. }
  266. }
  267. .box_phone{
  268. height: 106upx;
  269. display: flex;
  270. align-items: center;
  271. justify-content: space-between;
  272. font-size: 28upx;
  273. color: #A6A6A6;
  274. border-bottom: 1upx solid #EBEBEB;
  275. border-top: 1upx solid #EBEBEB;
  276. div{
  277. display: flex;
  278. align-items: center;
  279. }
  280. .img{
  281. width: 26upx;
  282. height: 22upx;
  283. }
  284. span{
  285. color: #333333;
  286. font-size: 32upx;
  287. padding-right: 18upx;
  288. font-weight: bold;
  289. }
  290. }
  291. .box_qita{
  292. height: 106upx;
  293. font-size: 28upx;
  294. color: #7CA4FC;
  295. line-height: 106upx;
  296. }
  297. .boxs{
  298. height: 50upx;
  299. }
  300. .box_btns{
  301. margin-top: 10upx;
  302. display: flex;
  303. justify-content: space-between;
  304. .box_btn{
  305. width: 324upx;
  306. height: 82upx;
  307. font-size: 32upx;
  308. display: flex;
  309. align-items: center;
  310. justify-content: center;
  311. border-radius: 4upx;
  312. }
  313. .box_btn1{
  314. background: #F3F3F3;
  315. color: #33B925;
  316. }
  317. .box_btn2{
  318. background: #37962B;
  319. color: #FFFFFF;
  320. }
  321. }
  322. }
  323. }
  324. </style>