index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <view class="content">
  3. <image class="logo" src="/static/bg-home.jpg" mode="widthFix" :style="{marginTop:marginTopCss}"></image>
  4. <view class="getPhone-box" :style="{ bottom: bottomCss}">
  5. <button type="primary" class="custom-btn" open-type="getPhoneNumber"
  6. @getphonenumber="getPhoneNumber($event,'custom')" >观展登录</button>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. var md5 = require("../../common/md5.js");
  12. export default {
  13. components: {
  14. },
  15. data() {
  16. return {
  17. title: 'Hello',
  18. pageInfo:{},
  19. isAuth:getApp().globalData.isAuth,
  20. isAuthPhone:getApp().globalData.user_phone,
  21. productList:[
  22. ],
  23. bottomCss:'15%',
  24. marginTopCss:'0',
  25. userInfoObj:{},
  26. // phoneHeight:'',
  27. }
  28. },
  29. onLoad() {
  30. this.getEquipmentHeight();
  31. uni.hideTabBar({})
  32. console.log('onload')
  33. // getApp().globalData.lastId = options.scene ? options.scene : getApp().globalData.user_id
  34. },
  35. onShow() {
  36. this.loginRequest();
  37. console.log('onshow')
  38. },
  39. onShareAppMessage() {
  40. return {
  41. title: '科尔卡诺展会入场登记',
  42. path:'/pages/index/index'
  43. }
  44. },
  45. methods: {
  46. getEquipmentHeight(){
  47. console.log('getHeight')
  48. let phoneHeight = uni.getSystemInfoSync().windowHeight;
  49. console.log(phoneHeight)
  50. this.bottomCss = phoneHeight > 640 ? '25%':'15%';
  51. if(phoneHeight > 820){
  52. this.bottomCss = '35%';
  53. }
  54. },
  55. getPhoneNumber(e,type){
  56. let that = this;
  57. console.log(type)
  58. if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
  59. that.phoneRequest(e.detail.iv, e.detail.encryptedData, that.userInfoObj.session_key,type)
  60. } else { //
  61. uni.showToast({
  62. title: '您已拒绝授权登录',
  63. icon: 'none'
  64. });
  65. }
  66. },
  67. phoneRequest(myIv,myEncryptedData,sKey,type){
  68. let that = this;
  69. uni.request({
  70. url:getApp().globalData.shareUrl, //需要设置为全局
  71. method: 'POST',
  72. header: {
  73. 'content-type': 'application/x-www-form-urlencoded'
  74. },
  75. data: {
  76. method: 'auth',
  77. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  78. sign: md5('auth' + getApp().globalData.globalTimestamp),
  79. iv:myIv,
  80. session_key:sKey,
  81. encryptedData:myEncryptedData,
  82. },
  83. success: res => {
  84. // getApp().globalData.user_phone = res.data.phoneNumber;
  85. console.log(res)
  86. if(res.data.code === 200){
  87. getApp().globalData.userPhone = res.data.msg.phone;
  88. uni.navigateTo({
  89. url: '/pages/index/customPage/index',
  90. success: res => {},
  91. fail: () => {},
  92. complete: () => {},
  93. })
  94. }else {
  95. uni.showToast({
  96. title: res.data.msg,
  97. icon: 'none'
  98. });
  99. }
  100. }
  101. });
  102. },
  103. judgeUserType(type,pass){
  104. console.log(type,pass)
  105. switch (true){
  106. case type === 3: //需要授权
  107. console.log(type,pass)
  108. break;
  109. case type === 1 : //普通用户且允许入场
  110. uni.redirectTo({
  111. url: '/pages/index/successPage/index?types='+'custom', //游客成功页面
  112. success: res => {},
  113. fail: () => {},
  114. complete: () => {}
  115. })
  116. break;
  117. default:
  118. break;
  119. }
  120. },
  121. loginRequest(){
  122. let that = this;
  123. uni.login({
  124. success: (res) => {
  125. console.log(res.code)
  126. uni.request({
  127. url: getApp().globalData.shareUrl, //需要设置为全局
  128. method: 'POST',
  129. header: {
  130. 'content-type': 'application/x-www-form-urlencoded'
  131. },
  132. data: {
  133. method: 'login',
  134. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  135. code: res.code,
  136. sign: md5('login' + getApp().globalData.globalTimestamp)
  137. },
  138. success: res => {
  139. // 通过openid发起会员登录
  140. //type 1-普通客户 2-经销商客户 3-不存在需授权登录
  141. //pass 0-未知 1-允许入场 -1 - 禁止入场 ,
  142. if(res.data.code === 200){
  143. that.userInfoObj = res.data.msg;
  144. getApp().globalData.openId = that.userInfoObj.openid;
  145. getApp().globalData.userCodeNumber = that.userInfoObj.code;
  146. getApp().globalData.managerPhone = that.userInfoObj.qyjl_phone;
  147. getApp().globalData.managerName = that.userInfoObj.qyjl_name;
  148. getApp().globalData.addTime = that.userInfoObj.addtime;
  149. that.judgeUserType(that.userInfoObj.type,that.userInfoObj.pass)
  150. }else {
  151. uni.showToast({
  152. title: res.data.msg,
  153. icon: 'none'
  154. });
  155. }
  156. getApp().globalData.session_key = res.data.msg.session_key;
  157. }
  158. });
  159. }
  160. });
  161. },
  162. }
  163. }
  164. </script>
  165. <style lang="scss">
  166. .content {
  167. display: flex;
  168. flex-direction: column;
  169. align-items: center;
  170. justify-content: center;
  171. // height: 100%;
  172. // background-image: url('/static/bg-home.jpg');
  173. // background-repeat: no-repeat;
  174. // background-size: 100% 100%;
  175. }
  176. .more-height{
  177. height: 100%!important;
  178. }
  179. /* #ifdef MP-WEIXIN */
  180. .relevance {
  181. width: 100%;
  182. // height: 10px;
  183. // position: absolute;
  184. // top: 0;
  185. z-index: 999;
  186. }
  187. /* #endif */
  188. .logo {
  189. width: 100%;
  190. position: relative;
  191. // margin-top: 75px;
  192. }
  193. .getPhone-box {
  194. width: 100%;
  195. height: 200rpx;
  196. display: flex;
  197. justify-content: center;
  198. align-items: center;
  199. position: absolute;
  200. bottom: 25%;
  201. }
  202. .custom-btn {
  203. width: 230rpx;
  204. height: 80rpx;
  205. line-height:80rpx;
  206. color: #fff!important;
  207. background-color: rgb(136,143,137)!important;
  208. font-size: 30rpx!important;
  209. letter-spacing: 2rpx;
  210. margin: 0!important;
  211. padding: 0!important;
  212. }
  213. .dealer-btn {
  214. background-color: rgb(202,148,98)!important;
  215. }
  216. </style>