UNPKG

dd-vue-indexeslist

Version:

一个干净的轻量级移动端索引列表

2 lines 10.9 kB
(function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define([],e):"object"===typeof exports?exports["indexeslist"]=e():t["indexeslist"]=e()})("undefined"!==typeof self?self:this,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)r.d(n,s,function(e){return t[e]}.bind(null,s));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t["default"]}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s="fb15")}({"09db":function(t,e,r){"use strict";var n=r("d55d"),s=r.n(n);s.a},"230e":function(t,e,r){var n=r("d3f4"),s=r("7726").document,i=n(s)&&n(s.createElement);t.exports=function(t){return i?s.createElement(t):{}}},"6a99":function(t,e,r){var n=r("d3f4");t.exports=function(t,e){if(!n(t))return t;var r,s;if(e&&"function"==typeof(r=t.toString)&&!n(s=r.call(t)))return s;if("function"==typeof(r=t.valueOf)&&!n(s=r.call(t)))return s;if(!e&&"function"==typeof(r=t.toString)&&!n(s=r.call(t)))return s;throw TypeError("Can't convert object to primitive value")}},7726:function(t,e){var r=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=r)},"79e5":function(t,e){t.exports=function(t){try{return!!t()}catch(e){return!0}}},"7f7f":function(t,e,r){var n=r("86cc").f,s=Function.prototype,i=/^\s*function ([^ (]*)/,a="name";a in s||r("9e1e")&&n(s,a,{configurable:!0,get:function(){try{return(""+this).match(i)[1]}catch(t){return""}}})},"86cc":function(t,e,r){var n=r("cb7c"),s=r("c69a"),i=r("6a99"),a=Object.defineProperty;e.f=r("9e1e")?Object.defineProperty:function(t,e,r){if(n(t),e=i(e,!0),n(r),s)try{return a(t,e,r)}catch(o){}if("get"in r||"set"in r)throw TypeError("Accessors not supported!");return"value"in r&&(t[e]=r.value),t}},"9e1e":function(t,e,r){t.exports=!r("79e5")(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},c69a:function(t,e,r){t.exports=!r("9e1e")&&!r("79e5")(function(){return 7!=Object.defineProperty(r("230e")("div"),"a",{get:function(){return 7}}).a})},cb7c:function(t,e,r){var n=r("d3f4");t.exports=function(t){if(!n(t))throw TypeError(t+" is not an object!");return t}},d3f4:function(t,e){t.exports=function(t){return"object"===typeof t?null!==t:"function"===typeof t}},d55d:function(t,e,r){},fb15:function(t,e,r){"use strict";var n;(r.r(e),"undefined"!==typeof window)&&((n=window.document.currentScript)&&(n=n.src.match(/(.+\/)[^\/]+\.js(\?.*)?$/))&&(r.p=n[1]));r("7f7f");var s=function(){var t=this,e=t.$createElement,r=t._self._c||e;return r("div",{staticClass:"indexeslist bm-f1"},[r("div",{ref:"wrapper",staticClass:"wrapper"},[t._t("other"),r("div",{directives:[{name:"show",rawName:"v-show",value:""!=this.searchVal&&this.searchListData.length>0,expression:"this.searchVal != '' && this.searchListData.length > 0"}],staticClass:"bm-f1"},t._l(this.firstLetterArr,function(e,n){return r("div",{key:n,ref:"list-letter-container",refInFor:!0,staticClass:"list-letter-container"},[r("div",{ref:"search"+e.fl,refInFor:!0,staticClass:"list-letter-title"},[t._v(t._s(e.fl))]),t._l(e.data,function(s,i){return r("div",{key:i,staticClass:"list-letter-row-container",class:t.rowShow(s),on:{click:function(e){return t.listRowClick(n,i,s)}}},[t._t("list-letter-row-main-search",[r("div",[t._v("默认数据")])],{fl:e.fl,letterKey:n,listRowKey:i,listRowData:s,index:i,rowCount:e.data.length})],2)})],2)}),0),r("div",{directives:[{name:"show",rawName:"v-show",value:""!=this.searchVal&&this.searchListData.length<=0,expression:"this.searchVal != '' && this.searchListData.length <= 0"}],staticClass:"bm-f1"},[t._m(0)]),r("div",{directives:[{name:"show",rawName:"v-show",value:""==this.searchVal&&this.searchListData.length<=0,expression:"this.searchVal == '' && this.searchListData.length <= 0"}],staticClass:"bm-f1"},t._l(this.firstLetterArr,function(e,n){return r("div",{key:n,ref:"list-letter-container",refInFor:!0,staticClass:"list-letter-container"},[r("div",{ref:e.fl,refInFor:!0,staticClass:"list-letter-title"},[t._v(t._s(e.fl))]),t._l(e.data,function(s,i){return r("div",{key:i,staticClass:"list-letter-row-container",class:t.rowShow(s),on:{click:function(e){return t.listRowClick(n,i,s)}}},[t._t("list-letter-row-main",[r("div",[t._v("默认数据")])],{fl:e.fl,letterKey:n,listRowKey:i,listRowData:s,index:i,rowCount:e.data.length})],2)})],2)}),0)],2),r("div",{ref:"list-letter-nav",staticClass:"list-letter-nav bm bm-pc bm-ver"},t._l(this.letterNav,function(e,n){return r("div",{key:n,ref:"list-letter-nav-row-"+e.letter,refInFor:!0,staticClass:"list-letter-nav-row bm bm-ac bm-pc bm-f1",class:e.className?e.className:""},[t._v(t._s(e.letter))])}),0),r("div",{staticClass:"list-letter-toast",class:t.listLetterToast.className},[t._v(t._s(t.listLetterToast.value))])])},i=[function(){var t=this,e=t.$createElement,r=t._self._c||e;return r("div",{staticClass:"empty bm bm-ver bm-f1 bm-ac bm-pc"},[r("div",{staticClass:"icon bm bm-img"}),r("div",{staticClass:"text bm bm-ac bm-pc"},[t._v("未找到搜索结果")])])}],a={name:"indexeslist",props:["indexeslistData"],data:function(){return{firstLetter:{},firstLetterArr:[],letterArr:["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],letterNav:[],lastLetterNavKey:null,listLetterToast:{className:"",value:""},searchListData:[],searchVal:"",needUpdateLetter:!1}},created:function(){this.dataInit()},watch:{indexeslistData:{handler:function(t,e){this.dataInit()},deep:!0}},updated:function(){if(this.needUpdateLetter){this.needUpdateLetter=!1;var t=this;this.$nextTick(function(){t.letterNav.map(function(e,r){var n=t.$refs["list-letter-nav-row-"+e.letter][0],s=n.getBoundingClientRect();e.numArr=[s.top,s.top+s.height]})})}},methods:{dataInit:function(){var t=this,e=(t.indexeslistData.stringCode,t.indexeslistData.stringName,t.indexeslistData.stringSpell),r=t.indexeslistData.searcKeyWords||[];t.firstLetter={},t.firstLetterArr=[],t.letterNav=[],t.indexeslistData.data.map(function(n,s){n._searchKeyWord="",r.map(function(t,e){n._searchKeyWord+=n[t]+"_"});var i=n[e].substring(0,1).toUpperCase();t.firstLetter[i]||(t.firstLetter[i]={data:[]}),t.firstLetter[i].fl=i,t.firstLetter[i].data.push(n)}),t.letterArr.map(function(e){t.firstLetter[e]&&(t.letterNav.push({letter:e}),t.firstLetterArr.push(t.firstLetter[e]))}),this.$nextTick(function(){t.incident()})},incident:function(){var t=this;t.letterNav.map(function(e,r){var n=t.$refs["list-letter-nav-row-"+e.letter][0],s=n.getBoundingClientRect();e.numArr=[s.top,s.top+s.height],s.top<=0&&(t.needUpdateLetter=!0)}),t.$refs["list-letter-nav"].addEventListener("touchmove",function(e){t.listLetterNav(e,"","","press")},!1),t.$refs["list-letter-nav"].addEventListener("touchstart",function(e){t.listLetterNav(e,"","","press")},!1),t.$refs["list-letter-nav"].addEventListener("touchend",function(e){t.listLetterNav(e,"","","loosen")},!1),t.$refs["list-letter-nav"].addEventListener("touchcancel",function(e){t.listLetterNav(e,"","","loosen")},!1)},listLetterNav:function(t,e,r,n){var s=this;if("press"==n){var i=t.changedTouches?t.changedTouches[0]:t,a=Math.floor((i.clientY-s.letterNav[0].numArr[0])/24);if(s.lastLetterNavKey!=a&&(s.lastLetterNavKey?(s.$set(s.letterNav[this.lastLetterNavKey],"className",""),s.lastLetterNavKey=null):s.$set(s.letterNav[0],"className",""),this.letterNav[a])){var o=this.letterNav[a].letter;s.listLetterToastShow("toast-in",o),s.$set(s.letterNav[a],"className","letter-in"),s.lastLetterNavKey=a,s.listScrollTo(o)}}"loosen"==n&&(s.listLetterToastShow("",""),s.letterNav.map(function(t,e){s.$set(s.letterNav[e],"className","")}),s.lastLetterNavKey=null),t.preventDefault()},listLetterToastShow:function(t,e){this.listLetterToast.className=t,this.listLetterToast.value=e},listScrollTo:function(t){""!=this.searchVal&&this.searchListData.length>0?this.$refs.wrapper.scrollTop=this.$refs["search"+t][0].offsetTop:this.$refs.wrapper.scrollTop=this.$refs[t][0].parentNode.parentNode.offsetTop+this.$refs[t][0].offsetTop},searchList:function(t){if(!t||""==t)return this.searchVal="",this.searchListData=[],void this.dataInit();var e=this;e.searchVal=t;var r=t.toUpperCase();e.searchListData=[],e.firstLetterArr=[],e.firstLetter={},e.letterNav=[],e.indexeslistData.data.map(function(t,n){if(t._searchKeyWord.toUpperCase().indexOf(r)>=0){e.searchListData.push(t);var s=t[e.indexeslistData.stringSpell].substring(0,1).toUpperCase();e.firstLetter[s]||(e.firstLetter[s]={data:[]}),e.firstLetter[s].fl=s,e.firstLetter[s].data.push(t)}}),e.letterArr.map(function(t){e.firstLetter[t]&&(e.letterNav.push({letter:t}),e.firstLetterArr.push(e.firstLetter[t]))}),this.$nextTick(function(){e.incident()})},rowShow:function(t){return t.rowShow?t.rowShow:(t.rowShow="row-out",t.rowShow)},listRowClick:function(t,e,r){this.lastSelectedKey&&this.$set(this.firstLetterArr[this.lastSelectedKey.letterKey].data[this.lastSelectedKey.rowKey],"rowShow","row-out"),this.lastSelectedKey={letterKey:t,rowKey:e},this.$set(this.firstLetterArr[t].data[e],"rowShow","row-in"),this.$forceUpdate(),this.$emit("click",r)}}},o=a;r("09db");function l(t,e,r,n,s,i,a,o){var l,c="function"===typeof t?t.options:t;if(e&&(c.render=e,c.staticRenderFns=r,c._compiled=!0),n&&(c.functional=!0),i&&(c._scopeId="data-v-"+i),a?(l=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"===typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),s&&s.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(a)},c._ssrRegister=l):s&&(l=o?function(){s.call(this,this.$root.$options.shadowRoot)}:s),l)if(c.functional){c._injectStyles=l;var f=c.render;c.render=function(t,e){return l.call(e),f(t,e)}}else{var u=c.beforeCreate;c.beforeCreate=u?[].concat(u,l):[l]}return{exports:t,options:c}}var c=l(o,s,i,!1,null,"638c48a5",null),f=c.exports;f.install=function(t){t.component(f.name,f)};var u=f,d=[u],h=function t(e){t.installed||d.map(function(t){return e.component(t.name,t)})};"undefined"!==typeof window&&window.Vue&&h(window.Vue);var p={install:h,indexeslist:u};e["default"]=p}})}); //# sourceMappingURL=indexeslist.umd.min.js.map