UNPKG

@ctsy/layui-vue

Version:

a component library for Vue 3 base on layui-vue

121 lines (120 loc) 4.69 kB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); import { defineComponent, ref, computed, openBlock, createElementBlock, normalizeClass, createElementVNode, Fragment, renderList, unref, normalizeStyle, renderSlot, createTextVNode, toDisplayString, createCommentVNode } from "vue"; var index = ""; const _hoisted_1 = ["onMousemove", "onClick"]; const _hoisted_2 = { key: 0, class: "layui-inline" }; const __default__ = { name: "LayRate" }; const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, __default__), { props: { theme: null, length: { default: 5 }, modelValue: { default: 0 }, readonly: { type: [Boolean, String], default: false }, half: { type: Boolean, default: false }, text: { type: Boolean, default: false }, isBlock: { type: Boolean, default: false }, icons: { default: () => [ "layui-icon-rate", "layui-icon-rate-half", "layui-icon-rate-solid" ] } }, emits: ["update:modelValue", "select"], setup(__props, { emit }) { const props = __props; const currentValue = ref(props.modelValue); const tempValue = ref(currentValue.value); const isHalf = computed(() => props.half && Math.round(currentValue.value) !== currentValue.value); const getValue = function(index2, event) { if (!props.half) { return index2; } return index2 - (event.offsetX <= event.target.offsetWidth / 2 ? 0.5 : 0); }; const mousemove = function(index2, event) { if (props.readonly) { return false; } currentValue.value = getValue(index2, event); }; const mouseleave = function() { if (props.readonly) { return false; } currentValue.value = tempValue.value; }; const action = function(index2, event) { if (props.readonly) { return false; } currentValue.value = getValue(index2, event); tempValue.value = currentValue.value; emit("update:modelValue", currentValue.value); emit("select", currentValue.value); }; return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { class: normalizeClass(__props.isBlock ? "layui-block" : "layui-inline") }, [ createElementVNode("ul", { class: "layui-rate", onMouseleave: mouseleave }, [ (openBlock(true), createElementBlock(Fragment, null, renderList(__props.length, (index2) => { return openBlock(), createElementBlock("li", { key: index2, class: "layui-inline", onMousemove: ($event) => mousemove(index2, $event), onClick: ($event) => action(index2, $event) }, [ index2 <= Math.ceil(currentValue.value) ? (openBlock(), createElementBlock("i", { key: 0, class: normalizeClass([ "layui-icon", `${__props.icons[__props.icons.length - (unref(isHalf) && index2 === Math.ceil(currentValue.value) ? 2 : 1)]}` ]), style: normalizeStyle({ color: __props.theme }) }, null, 6)) : (openBlock(), createElementBlock("i", { key: 1, class: normalizeClass(["layui-icon"].concat(__props.icons[0])), style: normalizeStyle({ color: __props.theme }) }, null, 6)) ], 40, _hoisted_1); }), 128)) ], 32), __props.text ? (openBlock(), createElementBlock("span", _hoisted_2, [ renderSlot(_ctx.$slots, "default", { value: currentValue.value }, () => [ createTextVNode(toDisplayString(currentValue.value + "\u661F"), 1) ]) ])) : createCommentVNode("", true) ], 2); }; } })); _sfc_main.install = (app) => { app.component(_sfc_main.name, _sfc_main); }; export { _sfc_main as default };