index.vue 6.6 KB

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