GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • https://blog.wipi.tech/ramiko/editor

This view

  • Original page
  • New address

GeezerVison is showing www.v2ex.com — 使用 React 构建页面可视化搭建工具 - V2EX

Home Sign Up Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
custw
V2EX  ›  程序员

使用 React 构建页面可视化搭建工具

 
  custw ·
fantasticit · Jun 27, 2020 · 6598 views
This topic created in 2345 days ago, the information mentioned may be changed or developed.

前言

端午闲来无事,决定尝试下一个页面搭建工具。效果如下:

可以访问以下链接进行体验。

  • 编辑器:https://blog.wipi.tech/ramiko/editor
  • demo:https://blog.wipi.tech/ramiko/page/85333d78-ed24-4adf-8d09-b185fddd73fc

技术栈

  • React.js
  • nest.js
  • MySQL

思路

  1. 定义页面数据结构

既然是可视化页面搭建,那么页面必须可以以某种数据结构进行描述。比如:

{
    setting: {}; // 页面设置
    components: [] // 页面使用到的组件
}
  1. 定义组件数据结构

页面核心是由组件搭建而成的,那么就要定义组件的数据结构。

{
    name: "BaseTitle"
    props: {}
    schema: {}
}

组件都是 React 组件,这里保存组件的名称,前端渲染时,通过名字找到组件,进行渲染。

  1. 如何进行组件编辑

进行组件编辑,实际上编辑的是组件的 props,props 改变组件的渲染结果自然改变。为了对 props 进行编辑,需要定义 props 的描述语言,通过 props 描述来进行属性编辑。这里使用如下的 schema。

{
    title: "标题"
    type: "text"
}

对应组件 props.title,通过 type 可以决定如何渲染编辑器组件。

  1. 丰富功能

比如添加组件拖拽排序功能。

  1. 丰富函数

可能光能渲染组件是不够的,也许需要更多的功能包装,比如埋点。这一类函数本质上也是组件。可以通过 schema 定义进行 props 编辑。举个例子:

import React from 'react';

export const Tracking = ({ op, pageSn, pageElSn, children }) => {
  const onClick = () => {
    alert('埋点测试:' + op + '_' + pageSn + '_' + pageElSn);
  };

  return <div onClick={onClick}>{children}</div>;
};

Tracking.defaultProps = {
  op: 'click',
  pageSn: null,
  pageElSn: null
};

Tracking.schema = {
  op: {
    title: '曝光方式',
    type: 'radio',
    options: ['click', 'pv']
  },
  pageSn: {
    title: '页面编号',
    type: 'number'
  },
  pageElSn: {
    title: '元素编号',
    type: 'number'
  }
};

代码开源在 点击访问。

  • 组件
  • props
  • type
  • 页面
    5 replies  •  2020-07-30 14:25:36 +08:00
    ryderdu
    ryderdu
    Jun 28, 2020
    1
    云凤蝶 哈哈
    ryderdu
    ryderdu
    Jun 28, 2020
    2
    已 star
    custw
    custw
    OP
    Jun 28, 2020
    3
    @szdubinbin 和云凤蝶肯定没法比
    taowen
    taowen
    Jul 30, 2020
    4
    已收录到 https://github.com/taowen/awesome-lowcode/blob/master/README.md
    custw
    custw
    OP
    Jul 30, 2020
    5
    @taowen awesome
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1879 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 07:42 · PVG 15:42 · LAX 23:42 · JFK 02:42
    ♥ Do have faith in what you're doing.
    You are visitor 01402792 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.