@zhsz/cool-design-dv
Version:
100 lines (99 loc) • 2.42 kB
JavaScript
import { defineComponent, getCurrentInstance, useAttrs, onMounted, onBeforeUnmount, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle } from "vue";
import useMyChart from "../hooks/useMyChart.mjs";
import { DEFAULT_THEME } from "../utils/constant.mjs";
import { pickBy, isFunction } from "lodash-es";
const __default__ = defineComponent({
name: "MyChart"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
...__default__,
props: {
// 宽度
width: {
type: String,
default: "auto"
},
// 高度
height: {
type: String,
default: "400px"
},
// 适应父容器
fit: Boolean,
// ECharts 配置选项
options: {
type: Object
},
// 扩展 options
extend: [Object, Function],
// 主题
theme: {
type: [String, Object],
default() {
return DEFAULT_THEME;
}
},
// 显示加载动画
loading: Boolean,
// 打印 options
debug: {
type: Boolean
},
// 图表私有设置
settings: {
type: Object,
default() {
return {};
}
},
// 图表数据 echarts dataset
data: {
type: [Object, Array],
default() {
return {};
}
},
// 地图名称
map: String,
// 地图geojson对象或构建函数,函数必须返回Promise
register: [Object, Function],
// 地图注册成功回调
onRegister: Function,
// 坐标集合 如:{'广州': [120.3234, 33.4329]}, 或 [{label:'广州',value: [120.3234, 33.4329]}]
coords: {
type: [Object, Array],
default() {
return {};
}
}
},
emits: ["register"],
setup(__props, { emit: __emit }) {
var _a;
const props = __props;
const instance = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy;
const $listeners = pickBy(useAttrs(), isFunction);
const emits = __emit;
const { registerMap, init, dispose, classes, styles } = useMyChart(
props,
instance,
$listeners,
emits
);
onMounted(() => {
registerMap().then(init);
});
onBeforeUnmount(() => {
dispose();
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", {
class: normalizeClass(unref(classes)),
style: normalizeStyle(unref(styles))
}, null, 6);
};
}
});
export {
_sfc_main as default
};