index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. }
  27. },
  28. onLoad(options) {
  29. this.getEquipmentHeight();
  30. console.log('onload')
  31. // getApp().globalData.lastId = options.scene ? options.scene : getApp().globalData.user_id
  32. },
  33. onShow() {
  34. console.log('onshow')
  35. },
  36. onShareAppMessage() {
  37. return {
  38. title: '科尔卡诺展会入场登记',
  39. path:'/pages/index/index'
  40. }
  41. },
  42. methods: {
  43. getEquipmentHeight(){
  44. let phoneHeight = uni.getSystemInfoSync().windowHeight;
  45. console.log(phoneHeight)
  46. this.bottomCss = phoneHeight > 672 ? '35%':'25%';
  47. if(phoneHeight > 820){
  48. this.bottomCss = '40%';
  49. }
  50. },
  51. getPhoneNumber(e,type){
  52. let that = this;
  53. console.log(type)
  54. if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
  55. type === 'dealer' ? uni.navigateTo({
  56. url: '/pages/index/dealerPage/index',
  57. success: res => {},
  58. fail: () => {},
  59. complete: () => {}
  60. }) : uni.navigateTo({
  61. url: '/pages/index/customPage/index',
  62. success: res => {},
  63. fail: () => {},
  64. complete: () => {},
  65. })
  66. //that.phoneRequest(e.detail.iv, e.detail.encryptedData, getApp().globalData.session_key)
  67. } else { //
  68. uni.showToast({
  69. title: '您已拒绝授权登录',
  70. icon: 'none'
  71. });
  72. }
  73. },
  74. phoneRequest(myIv,myEncryptedData,sKey){
  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: 'getPhoneNumber',
  84. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  85. uid:getApp().globalData.user_id,
  86. sign: md5('getPhoneNumber' + getApp().globalData.globalTimestamp),
  87. iv:myIv,
  88. sessionKey:sKey,
  89. encryptedData:myEncryptedData,
  90. },
  91. success: res => {
  92. // getApp().globalData.user_phone = res.data.phoneNumber;
  93. console.log(res)
  94. }
  95. });
  96. },
  97. getShareInfo(uid){
  98. uni.request({
  99. url: getApp().globalData.shareUrl, //需要设置为全局
  100. method: 'POST',
  101. header: {
  102. 'content-type': 'application/x-www-form-urlencoded'
  103. },
  104. data: {
  105. method: 'addShare',
  106. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  107. shangjiid:uid,
  108. userid:getApp().globalData.user_id,
  109. sign: md5('addShare' + getApp().globalData.globalTimestamp)
  110. },
  111. success: res => {
  112. console.log(res)
  113. }
  114. });
  115. },
  116. loginRequest(){
  117. uni.login({
  118. success: (res) => {
  119. uni.request({
  120. url: getApp().globalData.shareUrl, //需要设置为全局
  121. method: 'POST',
  122. header: {
  123. 'content-type': 'application/x-www-form-urlencoded'
  124. },
  125. data: {
  126. method: 'login',
  127. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  128. code: res.code,
  129. sign: md5('login' + getApp().globalData.globalTimestamp)
  130. },
  131. success: res => {
  132. // 通过openid发起会员登录
  133. console.log('userId',res.data.msg.id)
  134. console.log('lastId',getApp().globalData.lastId)
  135. getApp().globalData.user_id = res.data.msg.id;
  136. getApp().globalData.open_id = res.data.msg.openid;
  137. getApp().globalData.isAuth = res.data.msg.auth_status === '1';
  138. getApp().globalData.user_name = res.data.msg.name;
  139. getApp().globalData.user_headUrl = res.data.msg.headimg;
  140. getApp().globalData.session_key = res.data.msg.session_key;
  141. getApp().globalData.user_phone = res.data.msg.phone;
  142. getApp().globalData.user_status = res.data.msg.status;
  143. // getApp().globalData.times = res.data.msg.times;
  144. // getApp().globalData.total_times = res.data.msg.total_times;
  145. this.isAuth = getApp().globalData.isAuth;
  146. this.isAuthPhone = getApp().globalData.user_phone;
  147. let lastId = getApp().globalData.lastId ? getApp().globalData.lastId : res.data.msg.id;
  148. this.getPageInfo(res.data.msg.id);
  149. this.getShareInfo(lastId)
  150. }
  151. });
  152. }
  153. });
  154. },
  155. getPageInfo(uId){ //获取首页面基本信息接口
  156. uni.showLoading({
  157. title: '加载中',
  158. });
  159. let that = this;
  160. uni.request({
  161. url: getApp().globalData.shareUrl, //需要设置为全局
  162. method: 'POST',
  163. header: {
  164. 'content-type': 'application/x-www-form-urlencoded'
  165. },
  166. data: {
  167. method: 'getHomePageInfo',
  168. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  169. id: 1,
  170. sign: md5('getHomePageInfo' + getApp().globalData.globalTimestamp)
  171. },
  172. success: res => {
  173. if (res.data.code === 200) {
  174. uni.hideLoading();
  175. that.pageInfo = res.data.msg;
  176. getApp().globalData.shareImg = res.data.msg.picture;
  177. getApp().globalData.shareContent = res.data.msg.sharecontent;
  178. getApp().globalData.shareTaobaoCode = res.data.msg.copycontent;
  179. getApp().globalData.shareStoreImg = res.data.msg.heading;
  180. }
  181. }
  182. });
  183. },
  184. showShareModal(){
  185. // 需要在 popup 组件,指定 ref 为 popup
  186. if(this.isAuthPhone){
  187. this.$refs.popup.open();
  188. }else {
  189. uni.navigateTo({
  190. url: '../auth/index',
  191. success: res => {},
  192. fail: () => {},
  193. complete: () => {}
  194. });
  195. }
  196. },
  197. cancelModal(){
  198. // 需要在 popup 组件,指定 ref 为 popup
  199. this.$refs.popup.close();
  200. },
  201. goPostShare() {
  202. this.$refs.popup.close()
  203. uni.navigateTo({
  204. url: '/pages/index/postShare/index'
  205. })
  206. },
  207. }
  208. }
  209. </script>
  210. <style lang="scss">
  211. .content {
  212. display: flex;
  213. flex-direction: column;
  214. align-items: center;
  215. justify-content: center;
  216. // background-image: url('/static/bg-home.jpg');
  217. // background-repeat: no-repeat;
  218. // background-size: 100% 100%;
  219. }
  220. .logo {
  221. width: 100%;
  222. position: relative;
  223. }
  224. .getPhone-box {
  225. width: 100%;
  226. height: 200rpx;
  227. display: flex;
  228. justify-content: center;
  229. align-items: center;
  230. position: absolute;
  231. bottom: 25%;
  232. }
  233. .custom-btn {
  234. width: 230rpx;
  235. height: 80rpx;
  236. line-height:80rpx;
  237. color: #fff!important;
  238. background-color: rgb(136,143,137)!important;
  239. font-size: 30rpx!important;
  240. letter-spacing: 2rpx;
  241. margin: 0!important;
  242. padding: 0!important;
  243. }
  244. .dealer-btn {
  245. background-color: rgb(202,148,98)!important;
  246. }
  247. </style>