123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import { Transform } from "konva/lib/Util";
- import { themeMouseColors } from "@/constant/help-style.ts";
- import {
- BaseItem,
- generateSnapInfos,
- getBaseItem,
- getRectSnapPoints,
- } from "../util.ts";
- import { getMouseColors } from "@/utils/colors.ts";
- import { InteractiveFix, InteractiveTo } from "../index.ts";
- import { Size } from "@/utils/math.ts";
- export { default as Component } from "./table.vue";
- export { default as TempComponent } from "./temp-table.vue";
- export const shapeName = "表格";
- export const defaultStyle = {
- stroke: themeMouseColors.theme,
- strokeWidth: 1,
- fontSize: 16,
- align: "center",
- fontStyle: "normal",
- fontColor: themeMouseColors.theme,
- };
- export const defaultCollData = {
- fontFamily: "Calibri",
- fontSize: 16,
- align: "center",
- fontStyle: "normal",
- fontColor: themeMouseColors.theme,
- };
- export const addMode = "area";
- export type TableCollData = Partial<typeof defaultCollData> & Size & {
- content: string;
- padding: number
- readonly?: boolean
- notdel?: boolean
- };
- export type TableData = Partial<typeof defaultStyle> &
- BaseItem & Size & {
- notaddRow?: boolean
- notaddCol?: boolean
- mat: number[];
- content: TableCollData[][];
- };
- export const getMouseStyle = (data: TableData) => {
- const strokeStatus = getMouseColors(data.stroke || defaultStyle.stroke);
- return {
- default: { stroke: strokeStatus.pub },
- hover: { stroke: strokeStatus.hover },
- press: { stroke: strokeStatus.press },
- select: { select: strokeStatus.select },
- };
- };
- export const getSnapPoints = (data: TableData) => {
- const tf = new Transform(data.mat);
- const points = getRectSnapPoints(data.width, data.height, 0, 0)
- .map((v) => tf.point(v));
- return points
- };
- export const getSnapInfos = (data: TableData) => {
- return generateSnapInfos(getSnapPoints(data), true, false);
- };
- export const interactiveToData: InteractiveTo<"table"> = ({
- info,
- preset = {},
- ...args
- }) => {
- if (info.cur) {
- const item = {
- ...defaultStyle,
- ...getBaseItem(),
- ...preset,
- } as unknown as TableData;
- return interactiveFixData({ ...args, info, data: item });
- }
- };
- export const autoCollWidth = 100;
- export const autoCollHeight = 50;
- export const interactiveFixData: InteractiveFix<"table"> = ({
- data,
- info,
- notdraw
- }) => {
- if (info.cur) {
- const area = info.cur!;
- const origin = {
- x: Math.min(area[0].x, area[1].x),
- y: Math.min(area[0].y, area[1].y),
- }
- data.width = Math.abs(area[0].x - area[1].x)
- data.height = Math.abs(area[0].y - area[1].y)
-
- if (!notdraw || !(data.content?.length && data.content[0].length)) {
- const colNum = Math.floor(data.width / autoCollWidth) || 1;
- const rawNum = Math.floor(data.height / autoCollHeight) || 1;
- const temp = data.content?.[0]?.[0] || {
- content: ""
- };
- data.content = Array.from({ length: rawNum }, () =>
- Array.from({ length: colNum }, () => ({
- ...temp,
- width: data.width / colNum,
- height: data.height / rawNum,
- padding: 8
- }))
- );
- } else {
- const colHeight = data.height / data.content.length
- const colWidth = data.width / data.content[0].length
- data.content.forEach(row => {
- row.forEach(col => {
- col.width = colWidth
- col.height = colHeight
- col.padding = 8
- console.log(col.content)
- })
- })
- }
- data.mat = new Transform().translate(origin.x, origin.y).m;
- }
- return data;
- };
|