index.vue 7.0 KB

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