微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 line
5.8 KiB

  1. import * as UTIL from '../../utils/util.js';
  2. import * as API from '../../utils/API.js';
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. //底部自定义tabbar
  9. isSHowZDYTabBar: true,
  10. //底部弹框显示
  11. showDownTS: true,
  12. //顶部胶囊按钮位置信息rect
  13. CustomMenuButton: null,
  14. BarMarginLeft: 0,
  15. BarWidth: 0,
  16. list: [],
  17. isIPhoneX:false
  18. },
  19. /**
  20. * 计算bar 高度
  21. */
  22. computeBarLocation() {
  23. var that = this;
  24. let CustomMenuButton = wx.getMenuButtonBoundingClientRect();
  25. let CustomMenuButton_margin_right = wx.getSystemInfoSync().windowWidth - CustomMenuButton.right;
  26. let bar_margin_left = CustomMenuButton_margin_right + CustomMenuButton.width;
  27. let bar_width = wx.getSystemInfoSync().windowWidth - CustomMenuButton_margin_right * 2 - CustomMenuButton.width * 2;
  28. console.log("bar宽:" + bar_width + ";窗口宽度" + wx.getSystemInfoSync().windowWidth);
  29. that.setData({
  30. CustomMenuButton: CustomMenuButton,
  31. BarMarginLeft: bar_margin_left,
  32. BarWidth: bar_width
  33. });
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad: function (options) {
  39. let that = this;
  40. that.simulativeData();
  41. that.computeBarLocation();
  42. that.setData({
  43. isIPhoneX:UTIL.isIPhoneX()
  44. })
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady: function () {},
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: function () {},
  54. /**
  55. * 生命周期函数--监听页面隐藏
  56. */
  57. onHide: function () {},
  58. /**
  59. * 生命周期函数--监听页面卸载
  60. */
  61. onUnload: function () {},
  62. /**
  63. * 页面相关事件处理函数--监听用户下拉动作
  64. */
  65. onPullDownRefresh: function () {},
  66. /**
  67. * 页面上拉触底事件的处理函数
  68. */
  69. onReachBottom: function () {},
  70. /**
  71. * 用户点击右上角分享
  72. */
  73. onShareAppMessage: function () {},
  74. onItemClickMethod: function (e) {
  75. var that = this;
  76. var num = parseInt(e.currentTarget.id);
  77. console.log(num)
  78. switch (num) {
  79. case 0:
  80. //更新机制
  81. break;
  82. case 1:
  83. //网络访问
  84. that.httpTestMethod();
  85. break;
  86. case 4:
  87. //获取地理位置
  88. that.getLocationInfo();
  89. break;
  90. case 5:
  91. //全局loading
  92. that.showLoadingIcon();
  93. break;
  94. case 6:
  95. that.showModalConentMethod();
  96. break;
  97. case 7:
  98. that.showModalAllMethod();
  99. break;
  100. }
  101. },
  102. /**
  103. * 获取地理位置
  104. */
  105. getLocationInfo() {
  106. UTIL.getLocationFromWX(
  107. {
  108. success: (res) => {
  109. UTIL.showToastNoneIcon("当前经纬度:" + getApp().globalData.setInfo.latitude + "," + getApp().globalData.setInfo.longitude)
  110. }
  111. ,
  112. fail: (res) => {
  113. // wx.navigateTo({
  114. // url: '/pages/wxAuth/wxAuth',
  115. // })
  116. }
  117. }
  118. );
  119. }
  120. ,
  121. /**
  122. * loading小图标
  123. */
  124. showLoadingIcon() {
  125. UTIL.showLoadingHaveMask('数据加载中...');
  126. setTimeout(function () {
  127. UTIL.hideLoadingHaveMask();
  128. }, 2000)
  129. }
  130. ,
  131. /**
  132. * 显示提示框
  133. */
  134. showModalConentMethod() {
  135. UTIL.showModalNoneCancel('温馨提示', '这是一个按钮的弹框', '知道了');
  136. },
  137. /**
  138. * 显示完整提示框 并监听
  139. */
  140. showModalAllMethod() {
  141. UTIL.showModalOnClick('提示', '两个按钮并回调', 'OK', 'NO',
  142. {
  143. confirm() {
  144. UTIL.showToastNoneIcon('点击了OK');
  145. }
  146. ,
  147. cancel() {
  148. UTIL.showToastNoneIcon('点击了NO');
  149. }
  150. });
  151. }
  152. ,
  153. //底部弹框允许
  154. okOnClick(e) {
  155. console.log("底部弹框-允许");
  156. UTIL.showToastNoneIcon("底部弹框-允许");
  157. this.setData({
  158. showDownTS: true
  159. })
  160. },
  161. /**
  162. * 底部弹框-黑色背景点击
  163. */
  164. blackOnClick() {
  165. this.setData({
  166. showDownTS: true
  167. })
  168. }
  169. ,
  170. /**
  171. * 底部弹框拒绝
  172. */
  173. refuseOnClick() {
  174. console.log("底部弹框-拒绝");
  175. UTIL.showToastNoneIcon("底部弹框-拒绝");
  176. this.setData({
  177. showDownTS: true
  178. })
  179. },
  180. bindgetUserProfile(e) {
  181. UTIL.getUserInfoFomWX({
  182. success(res){
  183. UTIL.showToastNoneIcon("获取到昵称:"+getApp().globalData.wxUserInfo.nickName);
  184. }
  185. });
  186. }
  187. ,
  188. /**
  189. * 网络访问
  190. */
  191. httpTestMethod() {
  192. let sendData = {
  193. centerShopId: 10000,
  194. centerWarehouseId: 10051,
  195. channel: 220,
  196. channelType: 22,
  197. rows: 40,
  198. shopId: 10005,
  199. token: "LWXAPP1636599316684iv6qkhyqhr4izg",
  200. v: 3,
  201. warehouseId: 10005
  202. }
  203. // UTIL.httpRequest(API.URL_ZB_RECOMMEND_LIST, sendData,
  204. // {
  205. // success: (res) => {
  206. // if (res._code == API.SUCCESS_CODE) {
  207. // UTIL.showToastNoneIcon("数据共:" + res._data.length + "条");
  208. // } else {
  209. // UTIL.showToastNoneIcon(res._msg)
  210. // }
  211. // },
  212. // fail: (res) => {
  213. // UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  214. // },
  215. // complete: (res) => {
  216. // }
  217. // });
  218. }
  219. ,
  220. /**
  221. * 模拟数据
  222. */
  223. simulativeData() {
  224. let list = [
  225. {
  226. title: '更新机制(已嵌入)',
  227. },{
  228. title: '网络访问(点击获取)'
  229. },{
  230. title: '自动申请微信地理授权(已嵌入)'
  231. },{
  232. title: '获取微信OPenId(已嵌入)'
  233. },{
  234. title: '获取微信地理位置(点击获取)',
  235. tapBtn: 'getLocationInfo'
  236. },{
  237. title: 'loading小图标',
  238. tapBtn: 'showLoadingIcon'
  239. },{
  240. title: 'Modal弹框仅提示',
  241. tapBtn: 'showModalConentMethod',
  242. },{
  243. title: 'Modal两个按钮并监听',
  244. tapBtn: 'showModalAllMethod'
  245. }
  246. ];
  247. this.setData({
  248. list: list,
  249. })
  250. }
  251. })