index.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 4);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 4:
  90. /***/ (function(module, exports, __webpack_require__) {
  91. "use strict";
  92. var throttle = function throttle(func, wait, options) {
  93. var context = void 0;
  94. var args = void 0;
  95. var result = void 0;
  96. var timeout = null;
  97. var previous = 0;
  98. if (!options) options = {};
  99. var later = function later() {
  100. previous = options.leading === false ? 0 : Date.now();
  101. timeout = null;
  102. result = func.apply(context, args);
  103. if (!timeout) context = args = null;
  104. };
  105. return function () {
  106. var now = Date.now();
  107. if (!previous && options.leading === false) previous = now;
  108. var remaining = wait - (now - previous);
  109. context = this;
  110. args = arguments;
  111. if (remaining <= 0 || remaining > wait) {
  112. clearTimeout(timeout);
  113. timeout = null;
  114. previous = now;
  115. result = func.apply(context, args);
  116. if (!timeout) context = args = null;
  117. } else if (!timeout && options.trailing !== false) {
  118. timeout = setTimeout(later, remaining);
  119. }
  120. return result;
  121. };
  122. };
  123. Component({
  124. options: {
  125. addGlobalClass: true,
  126. pureDataPattern: /^_/
  127. },
  128. properties: {
  129. list: {
  130. type: Array,
  131. value: [],
  132. observer: function observer(newVal) {
  133. var _this = this;
  134. if (newVal.length === 0) return;
  135. var data = this.data;
  136. var alphabet = data.list.map(function (item) {
  137. return item.alpha;
  138. });
  139. this.setData({
  140. alphabet: alphabet,
  141. current: alphabet[0]
  142. }, function () {
  143. _this.computedSize();
  144. });
  145. }
  146. },
  147. vibrated: {
  148. type: Boolean,
  149. value: true
  150. }
  151. },
  152. data: {
  153. windowHeight: 612,
  154. current: 'A',
  155. intoView: '',
  156. touching: false,
  157. alphabet: [],
  158. _tops: [],
  159. _anchorItemH: 0,
  160. _anchorItemW: 0,
  161. _anchorTop: 0,
  162. _listUpperBound: 0
  163. },
  164. lifetimes: {
  165. created: function created() {},
  166. attached: function attached() {
  167. this.__scrollTo = throttle(this._scrollTo, 100, {});
  168. this.__onScroll = throttle(this._onScroll, 100, {});
  169. var _wx$getSystemInfoSync = wx.getSystemInfoSync(),
  170. windowHeight = _wx$getSystemInfoSync.windowHeight;
  171. this.setData({ windowHeight: windowHeight });
  172. }
  173. },
  174. methods: {
  175. choose: function choose(e) {
  176. var item = e.target.dataset.item;
  177. this.triggerEvent('choose', { item: item });
  178. },
  179. scrollTo: function scrollTo(e) {
  180. this.__scrollTo(e);
  181. },
  182. _scrollTo: function _scrollTo(e) {
  183. var data = this.data;
  184. var clientY = e.changedTouches[0].clientY;
  185. var index = Math.floor((clientY - data._anchorTop) / data._anchorItemH);
  186. var current = data.alphabet[index];
  187. this.setData({ current: current, intoView: current, touching: true });
  188. if (data.vibrated) wx.vibrateShort();
  189. },
  190. computedSize: function computedSize() {
  191. var data = this.data;
  192. var query = this.createSelectorQuery();
  193. query.selectAll('.index_list_item').boundingClientRect(function (rects) {
  194. var result = rects;
  195. data._tops = result.map(function (item) {
  196. return item.top;
  197. });
  198. }).exec();
  199. query.select('.anchor-list').boundingClientRect(function (rect) {
  200. data._anchorItemH = rect.height / data.alphabet.length;
  201. data._anchorItemW = rect.width;
  202. data._anchorTop = rect.top;
  203. }).exec();
  204. query.select('.page-select-index').boundingClientRect(function (rect) {
  205. data._listUpperBound = rect.top;
  206. });
  207. },
  208. removeTouching: function removeTouching() {
  209. var _this2 = this;
  210. setTimeout(function () {
  211. _this2.setData({ touching: false });
  212. }, 150);
  213. },
  214. onScroll: function onScroll(e) {
  215. this.__onScroll(e);
  216. },
  217. _onScroll: function _onScroll(e) {
  218. var data = this.data;
  219. var _tops = data._tops,
  220. alphabet = data.alphabet;
  221. var scrollTop = e.detail.scrollTop;
  222. var current = '';
  223. if (scrollTop < _tops[0]) {
  224. current = alphabet[0];
  225. } else {
  226. for (var i = 0, len = _tops.length; i < len - 1; i++) {
  227. if (scrollTop >= _tops[i] && scrollTop < _tops[i + 1]) {
  228. current = alphabet[i];
  229. }
  230. }
  231. }
  232. if (!current) current = alphabet[alphabet.length - 1];
  233. this.setData({ current: current });
  234. }
  235. }
  236. });
  237. /***/ })
  238. /******/ });