index.vue 7.0 KB

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