微信小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

315 linhas
6.4 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. case 8:
  101. that.showMoRenTab();
  102. break;
  103. case 9:
  104. that.showZDYTab();
  105. break;
  106. }
  107. },
  108. /**
  109. * 默认tab
  110. */
  111. showMoRenTab() {
  112. console.log('11111')
  113. wx.showTabBar({
  114. animation: false,
  115. })
  116. this.setData({
  117. isSHowZDYTabBar: true
  118. })
  119. }
  120. ,
  121. /**
  122. * 自定义tab
  123. */
  124. showZDYTab() {
  125. wx.hideTabBar({
  126. animation: false,
  127. })
  128. this.setData({
  129. isSHowZDYTabBar: false
  130. })
  131. }
  132. ,
  133. /**
  134. * 获取地理位置
  135. */
  136. getLocationInfo() {
  137. UTIL.getLocationFromWX(
  138. {
  139. success: (res) => {
  140. UTIL.showToastNoneIcon("当前经纬度:" + getApp().globalData.setInfo.latitude + "," + getApp().globalData.setInfo.longitude)
  141. }
  142. ,
  143. fail: (res) => {
  144. wx.navigateTo({
  145. url: '/pages/wxAuth/wxAuth',
  146. })
  147. }
  148. }
  149. );
  150. }
  151. ,
  152. /**
  153. * loading小图标
  154. */
  155. showLoadingIcon() {
  156. UTIL.showLoadingHaveMask('数据加载中...');
  157. setTimeout(function () {
  158. UTIL.hideLoadingHaveMask();
  159. }, 2000)
  160. }
  161. ,
  162. /**
  163. * 显示提示框
  164. */
  165. showModalConentMethod() {
  166. UTIL.showModalNoneCancel('温馨提示', '这是一个按钮的弹框', '知道了');
  167. },
  168. /**
  169. * 显示完整提示框 并监听
  170. */
  171. showModalAllMethod() {
  172. UTIL.showModalOnClick('提示', '两个按钮并回调', 'OK', 'NO',
  173. {
  174. confirm() {
  175. UTIL.showToastNoneIcon('点击了OK');
  176. }
  177. ,
  178. cancel() {
  179. UTIL.showToastNoneIcon('点击了NO');
  180. }
  181. });
  182. }
  183. ,
  184. //底部弹框允许
  185. okOnClick(e) {
  186. console.log("底部弹框-允许");
  187. UTIL.showToastNoneIcon("底部弹框-允许");
  188. this.setData({
  189. showDownTS: true
  190. })
  191. },
  192. /**
  193. * 底部弹框-黑色背景点击
  194. */
  195. blackOnClick() {
  196. this.setData({
  197. showDownTS: true
  198. })
  199. }
  200. ,
  201. /**
  202. * 底部弹框拒绝
  203. */
  204. refuseOnClick() {
  205. console.log("底部弹框-拒绝");
  206. UTIL.showToastNoneIcon("底部弹框-拒绝");
  207. this.setData({
  208. showDownTS: true
  209. })
  210. },
  211. bindgetUserProfile(e) {
  212. UTIL.getUserInfoFomWX({
  213. success(res){
  214. UTIL.showToastNoneIcon("获取到昵称:"+getApp().globalData.wxUserInfo.nickName);
  215. }
  216. });
  217. }
  218. ,
  219. /**
  220. * 网络访问
  221. */
  222. httpTestMethod() {
  223. let sendData = {
  224. centerShopId: 10000,
  225. centerWarehouseId: 10051,
  226. channel: 220,
  227. channelType: 22,
  228. memberId: 24892,
  229. rows: 40,
  230. shopId: 10005,
  231. token: "LWXAPP1636599316684iv6qkhyqhr4izg",
  232. v: 3,
  233. warehouseId: 10005
  234. }
  235. UTIL.httpRequest(API.URL_ZB_RECOMMEND_LIST, sendData,
  236. {
  237. success: (res) => {
  238. if (res._code == API.SUCCESS_CODE) {
  239. UTIL.showToastNoneIcon("数据共:" + res._data.length + "条");
  240. } else {
  241. UTIL.showToastNoneIcon(res._msg)
  242. }
  243. },
  244. fail: (res) => {
  245. UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  246. },
  247. complete: (res) => {
  248. }
  249. });
  250. }
  251. ,
  252. /**
  253. * 模拟数据
  254. */
  255. simulativeData() {
  256. let list = [
  257. {
  258. title: '更新机制(已嵌入)',
  259. },{
  260. title: '网络访问(点击获取)'
  261. },{
  262. title: '自动申请微信地理授权(已嵌入)'
  263. },{
  264. title: '获取微信OPenId(已嵌入)'
  265. },{
  266. title: '获取微信地理位置(点击获取)',
  267. tapBtn: 'getLocationInfo'
  268. },{
  269. title: 'loading小图标',
  270. tapBtn: 'showLoadingIcon'
  271. },{
  272. title: 'Modal弹框仅提示',
  273. tapBtn: 'showModalConentMethod',
  274. },{
  275. title: 'Modal两个按钮并监听',
  276. tapBtn: 'showModalAllMethod'
  277. },{
  278. title: '底部导航效果(默认)',
  279. tapBtn: 'showMoRenTab'
  280. },{
  281. title: '底部导航效果(自定义)',
  282. tapBtn: 'showZDYTab'
  283. }
  284. ];
  285. this.setData({
  286. list: list,
  287. })
  288. }
  289. })