zmp-vue
Version:
Build full featured iOS & Android apps using ZMP & Vue
118 lines (106 loc) • 3.11 kB
JavaScript
;
exports.__esModule = true;
exports.default = void 0;
var _vue = require("vue");
var _utils = require("../shared/utils");
var _mixins = require("../shared/mixins");
var _zmp = require("../shared/zmp");
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function render(_ctx, _cache) {
return (0, _vue.openBlock)(), (0, _vue.createBlock)("div", {
ref: "elRef",
class: _ctx.classes
}, [(0, _vue.renderSlot)(_ctx.$slots, "default")], 2);
}
var _default = {
name: 'zmp-list-index',
render: render,
props: _extends({
init: {
type: Boolean,
default: true
},
listEl: [String, Object],
indexes: {
type: [String, Array],
default: 'auto'
},
scrollList: {
type: Boolean,
default: true
},
label: {
type: Boolean,
default: false
},
iosItemHeight: {
type: Number,
default: 14
},
mdItemHeight: {
type: Number,
default: 14
},
auroraItemHeight: {
type: Number,
default: 14
}
}, _mixins.colorProps),
emits: ['listindex:select'],
setup: function setup(props, _ref) {
var emit = _ref.emit;
var zmpListIndex = null;
var elRef = (0, _vue.ref)(null);
var update = function update() {
if (!zmpListIndex) return;
zmpListIndex.update();
};
var scrollListToIndex = function scrollListToIndex(indexContent) {
if (!zmpListIndex) return;
zmpListIndex.scrollListToIndex(indexContent);
};
(0, _vue.watch)(function () {
return props.indexes;
}, function (newValue) {
if (!zmpListIndex) return;
zmpListIndex.params.indexes = newValue;
update();
});
(0, _vue.onMounted)(function () {
if (!props.init) return;
(0, _zmp.zmpready)(function () {
zmpListIndex = _zmp.zmp.listIndex.create({
el: elRef.value,
listEl: props.listEl,
indexes: props.indexes,
iosItemHeight: props.iosItemHeight,
mdItemHeight: props.mdItemHeight,
auroraItemHeight: props.auroraItemHeight,
scrollList: props.scrollList,
label: props.label,
on: {
select: function select(index, itemContent, itemIndex) {
emit('listindex:select', itemContent, itemIndex);
}
}
});
});
});
(0, _vue.onBeforeUnmount)(function () {
if (zmpListIndex && zmpListIndex.destroy) {
zmpListIndex.destroy();
}
zmpListIndex = null;
});
var classes = (0, _vue.computed)(function () {
return (0, _utils.classNames)('list-index', (0, _mixins.colorClasses)(props));
});
return {
elRef: elRef,
classes: classes,
update: update,
scrollListToIndex: scrollListToIndex
};
}
};
exports.default = _default;