@icreate/ics-mui
Version:
京东风格的轻量级移动端 Vue2、Vue3 组件库(支持小程序开发)
327 lines (326 loc) • 12.9 kB
JavaScript
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));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
import { defineComponent, ref, computed, nextTick, watch, openBlock, createElementBlock, createElementVNode, createBlock, withCtx, Fragment, renderList, createSlots, normalizeClass, toDisplayString, createCommentVNode, createVNode, createTextVNode } from "vue";
import { _ as _sfc_main$2 } from "../swipe.vue_vue_type_script_setup_true_lang-CmJC1O6r.js";
import { _ as _sfc_main$1 } from "../swipe-group.vue_vue_type_script_setup_true_lang-Dxpitxl3.js";
import { _ as _sfc_main$3 } from "../button.vue_vue_type_script_setup_true_lang-yMATZ2Sk.js";
import { showDialog } from "../dialog/Dialog.js";
import { w as withInstall } from "../with-install-DWwOiZS3.js";
const _hoisted_1 = { class: "medication" };
const _hoisted_2 = { class: "medication-box" };
const _hoisted_3 = { class: "name" };
const _hoisted_4 = {
key: 0,
class: "amount"
};
const _sfc_main = /* @__PURE__ */ defineComponent(__spreadProps(__spreadValues({}, {
name: "IcsMedication"
}), {
__name: "index",
props: {
modelValue: { type: Array, default: () => [] },
template: { type: Object, default: () => ({}) },
subAttributeList: { type: Array, default: () => [] },
disabled: { type: [Boolean, String, Number], default: false }
},
emits: ["update:modelValue", "click"],
setup(__props, { emit: __emit }) {
const props = __props;
const swipesRef = ref({});
const emits = __emit;
const template = computed(() => props.template);
const executeList = computed(() => props.modelValue);
const guid = (len = 32, firstU = true, radix = null) => {
const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
const uuid = [];
radix = radix || chars.length;
if (len) {
for (let i = 0; i < len; i++)
uuid[i] = chars[0 | Math.random() * radix];
} else {
let r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
uuid[14] = "4";
for (let i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random() * 16;
uuid[i] = chars[i == 19 ? r & 3 | 8 : r];
}
}
}
if (firstU) {
uuid.shift();
return `u${uuid.join("")}`;
}
return uuid.join("");
};
const getShowName = (value) => {
var _a;
return template.value && ((_a = template.value.children.filter((item) => item.id === value)[0]) == null ? void 0 : _a.showName);
};
const filteredEntries = (item) => {
const result2 = Object.entries(item).filter(([key]) => getShowName(key)).map(([key, value]) => ({ key, value }));
return result2;
};
function cleanString(str) {
if (typeof str !== "string") {
return str;
}
return str ? str.replace(/^[┌└│]+/, "") : "";
}
const firstItem = (item) => {
try {
return filteredEntries(item).filter((e) => e.key === template.value.children[0].id);
} catch (error) {
return [];
}
};
const secondItem = (item) => {
try {
return filteredEntries(item).filter((e) => e.key !== template.value.children[0].id);
} catch (error) {
return [];
}
};
const processList = () => {
const arr = [];
const findMatchingIndex = (list, startIndex, direction, marker) => {
var _a, _b;
for (let i = startIndex; i >= 0 && i < list.length; i += direction) {
if ((_b = list[i][(_a = firstItem(list[i])[0]) == null ? void 0 : _a.key]) == null ? void 0 : _b.includes(marker)) {
return i;
}
}
return -1;
};
const executeListArray = JSON.parse(JSON.stringify(executeList.value)).map((e, index) => {
e.index = index;
return e;
});
executeListArray.forEach((item, index) => {
var _a;
let catheterization = (_a = firstItem(item)[0]) == null ? void 0 : _a.value;
if (!catheterization || typeof catheterization !== "string" && !Array.isArray(catheterization)) {
arr.push([index, 1]);
return;
}
catheterization += "";
if (catheterization == null ? void 0 : catheterization.includes("┌")) {
const endIndex = findMatchingIndex(executeListArray, index + 1, 1, "└");
arr.push([index, endIndex !== -1 ? endIndex - index + 1 : 1]);
} else if (catheterization == null ? void 0 : catheterization.includes("│")) {
const startIndex = findMatchingIndex(executeListArray, index - 1, -1, "┌");
const endIndex = findMatchingIndex(executeListArray, index + 1, 1, "└");
const start = startIndex !== -1 ? startIndex : index;
const end = endIndex !== -1 ? endIndex : index;
arr.push([start, end - start + 1]);
} else if (catheterization == null ? void 0 : catheterization.includes("└")) {
const startIndex = findMatchingIndex(executeListArray, index - 1, -1, "┌");
arr.push([startIndex, startIndex !== -1 ? index - startIndex + 1 : 1]);
} else {
arr.push([index, 1]);
}
});
const uniqueArray = Array.from(new Set(arr.map((item) => JSON.stringify(item)))).map(
(item) => JSON.parse(item)
);
const newArr = uniqueArray.map(([start, count]) => ({
id: guid(),
children: executeListArray.slice(start, start + count).map((item) => {
item.id = guid();
item.show = filteredEntries(item).filter((e) => !!e.value).length > 0;
return item;
}).filter((e) => filteredEntries(e).filter((e2) => e2.value).length > 0)
}));
return newArr.filter((e) => e.children.length > 0);
};
const result = ref(processList());
const flattenedData = flattenData(result.value);
nextTick(() => {
emits("update:modelValue", flattenedData);
});
const showResult = (entry) => {
var _a, _b;
if (entry) {
const { key, value } = entry;
const subAttr = props.subAttributeList.find((attr) => attr.code === key);
return ((_b = (_a = subAttr == null ? void 0 : subAttr.attributeDetailList) == null ? void 0 : _a.find((detail) => detail.code === value)) == null ? void 0 : _b.name) || value;
} else {
return "";
}
};
watch(
() => props.modelValue,
() => {
result.value = processList();
},
{ deep: true }
);
function flattenData(data) {
const result2 = [];
data.forEach((item) => {
if (item.children && Array.isArray(item.children)) {
result2.push(...item.children);
}
});
return result2.map((_a) => {
var _b = _a, { id } = _b, rest = __objRest(_b, ["id"]);
console.log(id);
return rest;
});
}
const deleteItem = (item) => {
const del = () => {
const list = result.value.filter((i) => i.id !== item.id);
result.value = list;
const flattenedData2 = flattenData(list);
setTimeout(() => {
emits("update:modelValue", flattenedData2);
}, 100);
};
showDialog({
title: "提示",
content: `确认要删除吗?`,
popClass: "nut-dialog-class",
onOk: () => __async(this, null, function* () {
del();
}),
onCancel: () => {
var _a;
(_a = swipesRef.value[item.id]) == null ? void 0 : _a.close();
}
});
};
const onClick = (item) => {
if (props.disabled) {
return;
}
emits("click", item.children);
};
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", _hoisted_1, [
createElementVNode("div", _hoisted_2, [
result.value.length ? (openBlock(), createBlock(_sfc_main$1, {
key: 0,
lock: ""
}, {
default: withCtx(() => [
(openBlock(true), createElementBlock(Fragment, null, renderList(result.value, (item) => {
return openBlock(), createElementBlock("div", {
key: item.id,
class: "medication-list-swipe"
}, [
(openBlock(), createBlock(_sfc_main$2, {
ref_for: true,
ref: (el) => swipesRef.value[item.id] = el,
key: item.id + __props.disabled,
name: item.id,
class: "medication-list",
onClick: ($event) => onClick(item)
}, createSlots({
default: withCtx(() => [
createElementVNode("div", {
class: normalizeClass(["medication-card", { "merge-line": item.children.length > 1 }])
}, [
(openBlock(true), createElementBlock(Fragment, null, renderList(item.children, (site) => {
return openBlock(), createElementBlock("div", {
key: site.id,
class: "medication-card-item"
}, [
createElementVNode("span", _hoisted_3, toDisplayString(cleanString(showResult(firstItem(site)[0]))), 1),
secondItem(site).length > 0 ? (openBlock(), createElementBlock("div", _hoisted_4, [
(openBlock(true), createElementBlock(Fragment, null, renderList(secondItem(site), (entry) => {
return openBlock(), createElementBlock("span", {
key: entry.key,
class: "amount-text"
}, toDisplayString(getShowName(entry.key)) + ":" + toDisplayString(showResult(entry)), 1);
}), 128))
])) : createCommentVNode("", true)
]);
}), 128))
], 2)
]),
_: 2
}, [
!__props.disabled ? {
name: "right",
fn: withCtx(() => [
createVNode(_sfc_main$3, {
shape: "square",
class: "del_btn",
type: "danger",
onClick: ($event) => deleteItem(item)
}, {
default: withCtx(() => [
createTextVNode(" 删除 ")
]),
_: 2
}, 1032, ["onClick"])
]),
key: "0"
} : void 0
]), 1032, ["name", "onClick"]))
]);
}), 128))
]),
_: 1
})) : createCommentVNode("", true)
])
]);
};
}
}));
withInstall(_sfc_main);
export {
_sfc_main as Medication,
_sfc_main as default
};