index.vue 6.5 KB

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