|
@@ -1,24 +1,162 @@
|
|
|
import { css } from "@linaria/core";
|
|
|
-import { PageListController } from "queenjs/framework/utils";
|
|
|
-import { defineComponent } from "vue";
|
|
|
+import { defineComponent, onMounted, onUnmounted, reactive, ref } from "vue";
|
|
|
import { useCtx } from "../../context";
|
|
|
+import { ShowItem } from "@/modules/list/state";
|
|
|
+import Dialog from "../list/dialog";
|
|
|
+import { conformsTo, divide } from "lodash";
|
|
|
+import dialog from "@/modules/list/actions/dialog";
|
|
|
+import { nextTick } from "process";
|
|
|
|
|
|
export default defineComponent({
|
|
|
setup() {
|
|
|
const ctx = useCtx();
|
|
|
- const { user, websiteUI } = ctx;
|
|
|
- const list = new PageListController(ctx);
|
|
|
+ const { list } = ctx;
|
|
|
+ const canvasRef = ref();
|
|
|
+ const cacheCanvasRef = ref();
|
|
|
+ const state = reactive({
|
|
|
+ scrollElement: [] as any,
|
|
|
+ dialogId: 0,
|
|
|
+ });
|
|
|
+
|
|
|
+ function clickItem(e: any, itemIndex: number) {
|
|
|
+ list.actions.addDialog(e, itemIndex);
|
|
|
+ }
|
|
|
+ const rows: number[] = [];
|
|
|
+ for (let i = 0; i < list.state.totalRow; i++) {
|
|
|
+ rows.push(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ const rootRef = ref<HTMLElement>();
|
|
|
+
|
|
|
+ onMounted(async () => {
|
|
|
+ await list.actions.initListCanvasDatas(
|
|
|
+ rootRef.value?.clientWidth as number,
|
|
|
+ rootRef.value?.clientHeight as number
|
|
|
+ );
|
|
|
+
|
|
|
+ list.actions.startListRunning(canvasRef.value);
|
|
|
+
|
|
|
+ return;
|
|
|
+
|
|
|
+ canvasRef.value.width = rootRef.value?.clientWidth;
|
|
|
+ canvasRef.value.height = rootRef.value?.clientHeight;
|
|
|
+ let cacheCanvas = document.createElement("canvas");
|
|
|
+ cacheCanvas.width = rootRef.value?.clientWidth;
|
|
|
+ cacheCanvas.height = rootRef.value?.clientHeight;
|
|
|
+ cacheCanvasRef.value = cacheCanvas;
|
|
|
+ canvasEvent();
|
|
|
+ canvasDraw();
|
|
|
+ scrollStart();
|
|
|
+ });
|
|
|
+
|
|
|
+ let timmerRef = ref<any>(0);
|
|
|
+ let speedRef = ref<number>(1);
|
|
|
+ onUnmounted(() => {
|
|
|
+ if (timmerRef.value) {
|
|
|
+ cancelAnimationFrame(timmerRef.value);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ const scrollStart = () => {
|
|
|
+ list.state.scrollOffset += speedRef.value;
|
|
|
+ if (list.state.scrollOffset == list.state.repeatWidth) {
|
|
|
+ cancelAnimationFrame(timmerRef.value);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ list.actions.updateCanvasItem(speedRef.value);
|
|
|
+ canvasDraw();
|
|
|
+ timmerRef.value = requestAnimationFrame(scrollStart);
|
|
|
+ };
|
|
|
+ const canvasDraw = () => {
|
|
|
+ let items = list.state.items;
|
|
|
+ let renderW = canvasRef.value.width;
|
|
|
+ let renderH = canvasRef.value.height;
|
|
|
+ let cacheCtx = cacheCanvasRef.value.getContext("2d");
|
|
|
+ cacheCtx.clearRect(0, 0, renderW + 1, renderH + 1);
|
|
|
+ items.map((item, i) => {
|
|
|
+ let image = new Image();
|
|
|
+ image.src = item.url;
|
|
|
+
|
|
|
+ cacheCtx.drawImage(image, item.x, item.y, item.w, item.h);
|
|
|
+ cacheCtx.font = "12px sans-serif";
|
|
|
+ cacheCtx.fillStyle = "#FFFFFF";
|
|
|
+ cacheCtx.textBaseline = "top";
|
|
|
+ let text =
|
|
|
+ item.name.length > 10 ? item.name.substring(0, 9) + "..." : item.name;
|
|
|
+ cacheCtx.fillText(text, item.x, item.y + item.h + 6);
|
|
|
+ });
|
|
|
+ let ctx = canvasRef.value.getContext("2d");
|
|
|
+ ctx.clearRect(0, 0, renderW + 1, renderH + 1);
|
|
|
+ ctx.drawImage(cacheCanvasRef.value, 0, 0, renderW, renderH);
|
|
|
+ };
|
|
|
+ const clickCol = (e: any) => {
|
|
|
+ let x = e.clientX;
|
|
|
+ let totalRow = list.state.totalRow;
|
|
|
+ const paddingW = list.state.paddingW;
|
|
|
+ const parentWidth = list.state.parentWidth;
|
|
|
+ for (let i = 0; i < totalRow; i++) {
|
|
|
+ const rowCount = list.state.rowCount;
|
|
|
+ const start = i * rowCount;
|
|
|
+ const end = start + rowCount;
|
|
|
+ const ItemWidth = Math.round(
|
|
|
+ (parentWidth - (totalRow + 1) * paddingW) / totalRow
|
|
|
+ );
|
|
|
+ const nowx = (i + 1) * paddingW + i * ItemWidth;
|
|
|
+ if (x > nowx && x < nowx + ItemWidth) {
|
|
|
+ let itemIndex = findItem(e, start, end);
|
|
|
+ clickItem(e, itemIndex);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const findItem = (e: any, start: number, end: number) => {
|
|
|
+ for (let i = start; i < end; i++) {
|
|
|
+ const item = list.state.items[i];
|
|
|
+ const x = e.clientX;
|
|
|
+ const y = e.clientY;
|
|
|
+ if (
|
|
|
+ x >= item.x &&
|
|
|
+ x <= item.x + item.w &&
|
|
|
+ y >= item.y &&
|
|
|
+ y <= item.y + item.h
|
|
|
+ ) {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const canvasEvent = () => {
|
|
|
+ canvasRef.value.addEventListener("click", (e) => {
|
|
|
+ clickCol(e);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ const MoveStart = (id: number) => {
|
|
|
+ state.dialogId = id;
|
|
|
+ };
|
|
|
+
|
|
|
return () => (
|
|
|
- <div class={rootStyle}>
|
|
|
- 首页{user.state.userInfo.username}
|
|
|
- <button onClick={user.actions.create}>getUserInfo</button>
|
|
|
- <button onClick={() => websiteUI.uploadImage()}>上传图片</button>
|
|
|
+ <div class={rootStyle} ref={rootRef}>
|
|
|
+ <canvas ref={canvasRef} />
|
|
|
+
|
|
|
+ {list.state.dialogs.map((item) => (
|
|
|
+ <Dialog data={item} key={item.id} onMove={MoveStart} />
|
|
|
+ ))}
|
|
|
</div>
|
|
|
);
|
|
|
},
|
|
|
});
|
|
|
|
|
|
const rootStyle = css`
|
|
|
- padding: 30px;
|
|
|
- background-color: red;
|
|
|
+ position: relative;
|
|
|
+ height: 100%;
|
|
|
+ width: 100%;
|
|
|
+ display: flex;
|
|
|
+ background-color: #3f322c;
|
|
|
+ overflow: hidden;
|
|
|
+ user-select: none;
|
|
|
+ flex-flow: row;
|
|
|
+ canvas {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ /* background-color: #fff; */
|
|
|
+ }
|
|
|
`;
|