index.vue 6.5 KB

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