@ccos/webos-vue
Version:
A Web-Ui Framework for Skyworth/Coocaa TV
96 lines (95 loc) • 3.62 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const common = require("./index45.js");
require("./index46.js");
const _pluginVue_exportHelper = require("./index34.js");
const _sfc_main = {
__name: "unit",
setup(__props) {
const curUnitRef = vue.ref(null);
const childRender = vue.ref(false);
const unitStyle = vue.reactive({});
let unitKey = 0;
let rowIndex = 0;
let colIndex = 0;
let segment = vue.inject("equal-divide-part-segment");
let unitWidth = vue.inject("equal-divide-part-unit-width");
let unitHeight = vue.inject("equal-divide-part-unit-height");
let unitKeyList = vue.inject("equal-divide-part-unit-keys");
let notifyUnitChanged = vue.inject("equal-divide-part-unit-changed");
function getKey() {
let randomNum1 = Math.floor(1e6 * Math.random());
let randomNum2 = Math.floor(1e6 * Math.random());
let randomNum3 = Math.floor(1e6 * Math.random());
let randomNum4 = Math.floor(1e6 * Math.random());
let randomNum5 = Math.floor(1e6 * Math.random());
let randomNum6 = Math.floor(1e6 * Math.random());
let key = `${randomNum1}-${randomNum2}-${randomNum3}-${randomNum4}-${randomNum5}-${randomNum6}`;
return key;
}
const addCurrentUnitKey = () => {
unitKey = getKey();
if (unitKeyList.value.indexOf(unitKey) < 0) {
unitKeyList.value.push(unitKey);
if (notifyUnitChanged) {
notifyUnitChanged();
}
}
};
const delCurrentUnitKey = () => {
let index = unitKeyList.value.indexOf(unitKey);
if (index < 0) {
return;
}
unitKeyList.value.splice(index, 1);
if (notifyUnitChanged) {
notifyUnitChanged();
}
};
const getCurrentUnitKeyIndex = (key) => {
return unitKeyList.value.indexOf(key);
};
const updateUnitLayout = (segment2, unitWidth2, unitHeight2) => {
if (!unitWidth2 || !unitHeight2 || segment2 <= 0) {
childRender.value = false;
return;
}
let unitIndex = getCurrentUnitKeyIndex(unitKey);
rowIndex = parseInt(unitIndex / segment2);
colIndex = unitIndex % segment2;
const x = colIndex * (unitWidth2 + common.gapValue);
const y = rowIndex * (unitHeight2 + common.gapValue);
unitStyle["position"] = "absolute";
unitStyle["width"] = "" + common.px2vw(unitWidth2) + "vw";
unitStyle["height"] = "" + common.px2vw(unitHeight2) + "vw";
unitStyle["left"] = "" + common.px2vw(x) + "vw";
unitStyle["top"] = "" + common.px2vw(y) + "vw";
childRender.value = true;
};
vue.onBeforeMount(() => {
});
vue.onMounted(() => {
});
vue.onBeforeUnmount(() => {
delCurrentUnitKey();
});
vue.watch([segment, unitWidth, unitHeight], ([segment2, unitWidth2, unitHeight2]) => {
updateUnitLayout(segment2, unitWidth2, unitHeight2);
});
addCurrentUnitKey();
updateUnitLayout(segment.value, unitWidth.value, unitHeight.value);
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div", {
ref_key: "curUnitRef",
ref: curUnitRef,
style: vue.normalizeStyle(unitStyle),
class: "unit1"
}, [
childRender.value ? vue.renderSlot(_ctx.$slots, "default", { key: 0 }, void 0, true) : vue.createCommentVNode("", true)
], 4);
};
}
};
const TvUnit = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-8cd35672"]]);
exports.default = TvUnit;