index.vue 6.2 KB

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