navigation-bar.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /**
  2. * 自定义头部导航组件,基于官方组件Navigation开发。
  3. *
  4. * <navigation-bar title="会员中心" bindgetBarInfo="getBarInfo"></navigation-bar>
  5. *
  6. * 组件属性列表
  7. * bindgetBarInfo {eventhandler} 组件实例载入页面时触发此事件,首参为event对象,event.detail携带当前导航栏信息,如导航栏高度 event.detail.topBarHeight
  8. * backImage {string} back按钮的图标地址
  9. * homeImage {string} home按钮的图标地址
  10. * bindback {eventhandler} 点击back按钮触发此事件响应函数
  11. * ext-class {string} 添加在组件内部结构的class,可用于修改组件内部的样式
  12. * title {string} 导航标题,如果不提供为空
  13. * background {string} 导航背景色,默认#ffffff
  14. * color {string} 导航字体颜色
  15. * dbclickBackTop {boolean} 是否开启双击返回顶部功能,默认true
  16. * border {boolean} 是否显示顶部边框,默认false
  17. * loading {boolean} 是否显示标题左侧的loading,默认false
  18. * show {boolean} 显示隐藏导航,隐藏的时候navigation的高度占位还在,默认true
  19. * left {boolean} 左侧区域是否使用slot内容,默认false
  20. * center {boolean} 中间区域是否使用slot内容,默认false
  21. *
  22. * Slot Name
  23. * left 左侧slot,在back按钮位置显示,当left属性为true的时候有效
  24. * center 标题slot,在标题位置显示,当center属性为true的时候有效
  25. *
  26. */
  27. module.exports =
  28. /******/ (function(modules) { // webpackBootstrap
  29. /******/ // The module cache
  30. /******/ var installedModules = {};
  31. /******/
  32. /******/ // The require function
  33. /******/ function __webpack_require__(moduleId) {
  34. /******/
  35. /******/ // Check if module is in cache
  36. /******/ if(installedModules[moduleId]) {
  37. /******/ return installedModules[moduleId].exports;
  38. /******/ }
  39. /******/ // Create a new module (and put it into the cache)
  40. /******/ var module = installedModules[moduleId] = {
  41. /******/ i: moduleId,
  42. /******/ l: false,
  43. /******/ exports: {}
  44. /******/ };
  45. /******/
  46. /******/ // Execute the module function
  47. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  48. /******/
  49. /******/ // Flag the module as loaded
  50. /******/ module.l = true;
  51. /******/
  52. /******/ // Return the exports of the module
  53. /******/ return module.exports;
  54. /******/ }
  55. /******/
  56. /******/
  57. /******/ // expose the modules object (__webpack_modules__)
  58. /******/ __webpack_require__.m = modules;
  59. /******/
  60. /******/ // expose the module cache
  61. /******/ __webpack_require__.c = installedModules;
  62. /******/
  63. /******/ // define getter function for harmony exports
  64. /******/ __webpack_require__.d = function(exports, name, getter) {
  65. /******/ if(!__webpack_require__.o(exports, name)) {
  66. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  67. /******/ }
  68. /******/ };
  69. /******/
  70. /******/ // define __esModule on exports
  71. /******/ __webpack_require__.r = function(exports) {
  72. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  73. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  74. /******/ }
  75. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  76. /******/ };
  77. /******/
  78. /******/ // create a fake namespace object
  79. /******/ // mode & 1: value is a module id, require it
  80. /******/ // mode & 2: merge all properties of value into the ns
  81. /******/ // mode & 4: return value when already ns object
  82. /******/ // mode & 8|1: behave like require
  83. /******/ __webpack_require__.t = function(value, mode) {
  84. /******/ if(mode & 1) value = __webpack_require__(value);
  85. /******/ if(mode & 8) return value;
  86. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  87. /******/ var ns = Object.create(null);
  88. /******/ __webpack_require__.r(ns);
  89. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  90. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  91. /******/ return ns;
  92. /******/ };
  93. /******/
  94. /******/ // getDefaultExport function for compatibility with non-harmony modules
  95. /******/ __webpack_require__.n = function(module) {
  96. /******/ var getter = module && module.__esModule ?
  97. /******/ function getDefault() { return module['default']; } :
  98. /******/ function getModuleExports() { return module; };
  99. /******/ __webpack_require__.d(getter, 'a', getter);
  100. /******/ return getter;
  101. /******/ };
  102. /******/
  103. /******/ // Object.prototype.hasOwnProperty.call
  104. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  105. /******/
  106. /******/ // __webpack_public_path__
  107. /******/ __webpack_require__.p = "";
  108. /******/
  109. /******/
  110. /******/ // Load entry module and return exports
  111. /******/ return __webpack_require__(__webpack_require__.s = 1);
  112. /******/ })
  113. /************************************************************************/
  114. /******/ ([
  115. /* 0 */,
  116. /* 1 */
  117. /***/ (function(module, exports, __webpack_require__) {
  118. "use strict";
  119. var app = getApp();
  120. Component({
  121. options: {
  122. multipleSlots: true,
  123. addGlobalClass: true
  124. },
  125. properties: {
  126. backImage: {
  127. type: String,
  128. value: '/static/icon/icon_back.svg'
  129. },
  130. homeImage: {
  131. type: String,
  132. value: '/static/icon/icon_home.png'
  133. },
  134. extClass: {
  135. type: String,
  136. value: ''
  137. },
  138. title: {
  139. type: String,
  140. value: ''
  141. },
  142. background: {
  143. type: String,
  144. value: '#ffffff'
  145. },
  146. color: {
  147. type: String,
  148. value: '#000000'
  149. },
  150. dbclickBackTop:{
  151. type:Boolean,
  152. value:true
  153. },
  154. border: {
  155. type: Boolean,
  156. value: false
  157. },
  158. loading: {
  159. type: Boolean,
  160. value: false
  161. },
  162. show: {
  163. type: Boolean,
  164. value: true,
  165. observer: '_showChange'
  166. },
  167. left: {
  168. type: Boolean,
  169. value: false
  170. },
  171. center: {
  172. type: Boolean,
  173. value: false
  174. },
  175. },
  176. data: {
  177. displayStyle: '',
  178. showBack:false
  179. },
  180. attached: function attached() {
  181. var _this = this;
  182. //动态计算导航栏尺寸
  183. var isSupport = !!wx.getMenuButtonBoundingClientRect;
  184. var rect = wx.getMenuButtonBoundingClientRect ? wx.getMenuButtonBoundingClientRect() : null;
  185. wx.getSystemInfo({
  186. success: function success(res) {
  187. var ios = !!(res.system.toLowerCase().search('ios') + 1);
  188. var statusBarHeight=res.statusBarHeight;
  189. var topBarHeight=ios ? (44 + statusBarHeight) : (48 + statusBarHeight);
  190. _this.setData({
  191. ios: ios,
  192. topBarHeight:topBarHeight,
  193. statusBarHeight:statusBarHeight,
  194. innerWidth: isSupport ? 'width:' + rect.left + 'px' : '',
  195. innerPaddingRight: isSupport ? 'padding-right:' + (res.windowWidth - rect.left) + 'px' : '',
  196. leftWidth: isSupport ? 'width:' + (res.windowWidth - rect.left) + 'px' : ''
  197. });
  198. _this.triggerEvent('getBarInfo', {topBarHeight,statusBarHeight});
  199. }
  200. });
  201. //back箭头处理的显示
  202. var pages=getCurrentPages()
  203. if(pages.length>1){
  204. this.setData({showBack:true})
  205. }
  206. },
  207. methods: {
  208. _showChange: function _showChange(show) {
  209. var displayStyle = 'opacity: ' + (show ? '1' : '0') + ';-webkit-transition:opacity 0.5s;transition:opacity 0.5s;';
  210. this.setData({
  211. displayStyle: displayStyle
  212. });
  213. },
  214. //点击back事件处理
  215. goBack: function () {
  216. wx.navigateBack();
  217. this.triggerEvent('back');
  218. console.log("goBack");
  219. },
  220. //返回首页
  221. goHome:function(){
  222. wx.reLaunch({
  223. url: '/pages/index/index'
  224. })
  225. },
  226. //双击返回顶部
  227. // doubleClick(e) {
  228. // console.log("doubleClick");
  229. // if (!this.data.dbclickBackTop){return}
  230. // if (this.timeStamp && (e.timeStamp - this.timeStamp < 300)) {
  231. // this.timeStamp = 0
  232. // wx.pageScrollTo({
  233. // scrollTop: 0,
  234. // duration: 300
  235. // })
  236. // } else {
  237. // this.timeStamp = e.timeStamp
  238. // }
  239. // }
  240. }
  241. });
  242. /***/ })
  243. /******/ ]);