提交 57f2e961 编写于 作者: 杨若瑜's avatar 杨若瑜

更新3.9版本

上级 e554b64e
# FrontendBlocks
#### 最近更新日志
2023年02月19日:增加了大家非常急需的Ctrl+Z撤销功能,调整了一下模板,给一个后台模板和表单模板
## 一软在手,前端无忧!超强FLEX布局工具!
#### 介绍 Introduce
## 简介
本软件是一款强大的所见即所得前端页面设计器,是低代码开发领域的基础建设,生成的代码不依赖于任何框架,实测可以将前端布局工作的耗时减少80%以上,最关键的是,它实现了人人都可以写前端页面的梦想。
不用写一行代码即可让设计师、前端开发人员轻松设计出前端代码的利器,100%还原设计稿不再是梦。对于Uniapp开发非常友好,可以快速生成组件和页面。
本软件可以生成HTML5代码、按2x生成手机端VUE代码、按1x生成电脑端VUE代码,也可以直接生成JSON串,供其他开发工具(包括自主研发的)进行二次加工。
本软件采用Apache 2.0协议开源,可以免费商用。如有任何问题欢迎反馈,让我们共同建设好该开源项目。突出代码贡献者将会把名字写入README.md中,欢迎贡献。
This software is a powerful WYSIWYG front-end page designer, which is the basic construction in the field of low code development. The generated code does not depend on any framework. The actual measurement can reduce the time consumption of front-end layout work by more than 80%. The most important thing is that it realizes the dream that everyone can write front-end pages.
Designers and front-end developers can easily design front-end code without writing a line of code. It is no longer a dream to 100% restore the design draft. It is very friendly to uniapp development and can generate components and pages quickly.
This software can generate HTML5 code, generate mobile phone Vue code by 2x, generate computer Vue code by 1X, or directly generate JSON string for secondary processing by other development tools (including self-developed).
This software is open source with Apache 2.0 licence and can be used for free in business. If you have any questions, please feedback. Let's build this open source project together. Outstanding code contributors will write their names in readme.md, welcome to contribute.
本软件采用Apache 2.0协议开源,可以免费商用。如有任何问题欢迎反馈,让我们共同建设好该开源项目。突出代码贡献者将会把名字写入README.md中,欢迎贡献。
## 最近更新日志
写在前面:因为这个项目纯为爱发电,本人没有从本项目获得任何收入,所以只能靠各位大佬的996来撑起这个项目,帮忙测测也是爱。有需要付费定制集成需求的朋友也可以联系我。
2024年03月31日(3.9版本):
1. 智能父子连字符关联:支持CSS名称连字符的父子关系关联,生成产物的命名更加省心
我们可以用连字符命名各个块,并且支持在块中嵌套块,这样我们就可以很方便的实现复杂的页面布局。
比如icon-btn,下面分别有icon-btn-image和icon-btn-text两个子元素,
那么在生成的时候会自动生成下面的这种代码:
```html
<div class="icon-btn" onclick="iconBtnClick()">
<img class="image"/>
<div class="text">图标文字</div>
</div>
<style>
.icon-btn{
box-sizing:border-box;
border-bottom:1px solid rgba(229, 229, 229, 1);
border-right:1px solid rgba(229, 229, 229, 1);
text-align:left;
display:flex;
position:relative;
height:92px;
width:33%;
flex-direction:column;
justify-content:center;
align-items:center;
}
.icon-btn{
user-select: none;
}
.icon-btn:hover{
opacity: 0.8;
}
.icon-btn:active{
opacity: 0.5;
}
.icon-btn>.image{
background-image:url(https://www.yumeisoft.com/demo-icon.jpg);
background-size:cover;
background-repeat:no-repeat;
background-position:center;
text-align:left;
width:32px;
height:32px;
}
.icon-btn>.text{
font-size:14px;
color:rgba(102, 102, 102, 1);
text-align:left;
display:flex;
position:relative;
width:100%;
flex-direction:column;
align-items:center;
}
</style>
```
2. 智能CSS精简:精简了生成的CSS代码,原来数千行的代码现如今只需几十行。对于结构相同并且所有子元素样式一模一样的,不会再生成新的block样式,而是直接复用之前的样式。
3. 对于名称为-btn、-button结尾的元素自动加上点击效果,并且自动添加点击事件,写业务代码更方便,生成完几乎直接就可以开写!
4. 增加了7个常用模板,可以更快速的构建布局。
5. 极速设置面板里增加了一键“设置随机占位图”按钮,立即就能给当前块加背景,快速获得图文并茂的效果。
6. 重写了导出vue和html的代码,现在导出规则已经和ToolsBar解耦,你可以更方便的写你想要的任何导出规则。
7. 导出界面增加了一键复制功能,粘贴到代码里就能用!更贴心。
历史更新日志:
2023年02月19日(3.7版本):增加了大家非常急需的Ctrl+Z撤销功能,调整了一下模板,给一个后台模板和表单模板
#### 软件美照
![alt](https://gitcode.net/yumeisoft/frontend-blocks/-/raw/master/doc/preview1.png)
![alt](https://gitcode.net/yumeisoft/frontend-blocks/-/raw/master/doc/preview2.png)
![alt](https://gitcode.net/yumeisoft/frontend-blocks/-/raw/master/doc/preview3.png)
......@@ -23,25 +87,23 @@ This software is open source with Apache 2.0 licence and can be used for free in
Online presentation address:
http://39.104.17.92/frontendBlocks/
#### 软件架构 Architecture
#### 软件架构
使用VUE2.0开发,开箱即用。所生成的代码采用Flex布局和流式布局,具备良好的自适应性,特殊需求下也可以支持绝对定位布局、固钉布局。
对于Uniapp移动端开发者而言,可以直接生成rpx单位的样式。
对于图片,建议自建图床进行维护,如果有图片素材希望随着设计稿而维护,可以上网搜索“图片转BASE64编码”,把编码当做图片地址粘过去也是一样的(生成的文件会较大)。
Developed with vue2.0, ready to use. The generated code adopts flex layout and streaming layout with adaptability. Sometimes in your project, it can also support absolute positioning layout and fixed layout.
For uniapp mobile developers, rpx unit can be directly generated instead of px.
For pictures, it's recommended to build a picture cloud server. If you need picture embed in your design file, you can search the Internet for "picture to Base64 code", and paste the code as the picture address (the generated file will be large).
#### 安装教程 How to Install
#### 安装教程
1. npm install
2. npm run serve
3. 用浏览器打开(Open this url in Chrome) http://localhost:9000/frontendBlocks/
3. 用浏览器打开 http://localhost:9000/frontendBlocks/
#### 独立部署教程
#### 独立部署教程 How to Deploy
1. npm run build
2. 把dist目录中的文件拷贝到服务器上,部署目录为frontendBlocks即可(copy files in 'dist' directory to your sever, deploy in apache/nginx and folder called 'frontendBlocks')
#### 使用说明 How to Use
#### 使用说明
1. 左侧图层面板可以点击“添加”按钮添加子元素
2. 设计时高度和设计时内距用来方便观察父子元素之间的关系,
......@@ -52,45 +114,19 @@ For pictures, it's recommended to build a picture cloud server. If you need pict
7. 当前的设计会被自动保存,待下次打开时可继续上次的设计稿继续设计,非常的人性化
8. 点击块上的小加号,可以很方便的追加新的块
1. On the left layer panel, click "add" to add sub element in target
2. The design-time height and the design-time internal distance are used to facilitate the observation of the relationship between parent and child elements,
3. The "InsertInto" tab of the left panel is derived from 'public/tools.json', where the filled blocks node is from the "generate reusable JSON string" under the "code generation" menu
4. The middle panel can adjust the adaptive width. If the mobile phone is designed, it is recommended to use 375px
5. On the right panel, when a block is selected, its attributes can be adjusted. In the advanced panel, the type of element can be set, and supported generate as 'input'
6. Your frontend design can be created, saved and read, and can be copied and pasted across tabs (very useful for reusing design drafts)
7. The current design will be automatically saved. When you open in browser at next time, you can continue the design of the previous design draft. It is user-friendly.
8. Click the small plus button on the block to easily add a new block
(English version needs someone to contribute i18n module or function)
#### 疑难解答 Troubleshoot
1. 为什么我不能撤销?
与传统设计软件不同,本软件产生的是实实在在的代码,因此增加撤销功能会增加前端运行时压力,考虑再三,决定不设计撤销功能。
2. 布局用不明白怎么办?
#### 疑难解答
1. 布局用不明白怎么办?
建议使用者先了解一下Flex布局。如果没有Flex布局基础可以先从这几步开始:设置父容器的“子元素排列”->设置子元素的宽度和高度->如果子元素的宽度和高度是百分比,则需要设置父容器的宽度和高度->给子元素设置一些可视化的效果,比如背景颜色、文本内容等等
3. 元素排列太紧密了,点不上怎么办?
2. 元素排列太紧密了,点不上怎么办?
可以把“设计时高度”和“设计时内距”拉大一点点,这样就能看到元素了,这两个设置不会影响输出效果。而且强烈建议在左侧“图层”面板中进行元素的点选,这样会更加精确
4. 为什么我设置了宽度或高度但实际上不是按我设置的值显示?而且为什么当我添加元素多起来的时候,所有元素都挤在一起了?
3. 为什么我设置了宽度或高度但实际上不是按我设置的值显示?而且为什么当我添加元素多起来的时候,所有元素都挤在一起了?
这是因为Flex布局下元素呈弹性效果,如果要保持一个元素固定宽度或高度,另一个元素自适应,请在固定宽高的元素上勾选“布局”->“弹性”->“钢化”。如果要实现一个可滚动的列表区,请将父元素勾选“布局”->“弹性”->“关闭弹性”
5. 有的元素里面子元素过多,导致页面出现滚动条或者影响了其他元素的布局怎么办?
4. 有的元素里面子元素过多,导致页面出现滚动条或者影响了其他元素的布局怎么办?
可以尝试设置“高级”->“子元素溢出设置”->“滚动条”,只要不是“未设置”,都会触发BFC机制,成为独立渲染区域,这样就不会出现溢出或影响其他元素布局的情况了。
6. 我的设计稿崩溃导致FrontendBlocks打不开,怎么办?
5. 我的设计稿崩溃导致FrontendBlocks打不开,怎么办?
尽管我极力避免软件出现崩溃,但事实上软件操作环境复杂,可能出现无法预料的BUG。可以按下F12,在应用(Application)->存储(Storage)->本地存储空间(Local Storage)中,把tempSave删掉,重新刷新界面即可。如果不涉密的话,可以将tempSave中的值复制出来提一个Issue,社区会尽快解决这个BUG。
1. Why can't I undo it?
Unlike traditional design software, this software produces real code in memory, so adding undo will increase the pressure on front-end runtime.
2. What can I do with the layout?
It is recommended that users first understand the Flex layout. If you don't have a Flex layout knowledge, you can start with these steps: Set the "child element arrangement" of the parent container - > Set the width and height of the child element - > If the width and height of the child element are a percentage, you need to set the width and height of the parent container - > Set some visual effects for the child element, such as background color, text content, and so on.
3. The elements are so tightly arranged that cannot click accurately?
You can increase the Design-Time Height and Design-Time Interval a little so that you can see the elements, which do not affect the output. It is also strongly recommended that elements be selected in the Layers panel on the left for more precision
4. Why did I set the width or height but not actually display it at the value I set? And why are all the elements crowded together when I add more?
This is because elements under the Flex layout have an elastic effect. To keep one element fixed width or height and the other element adaptive, check Layout -> Elasticity -> Tempering on elements with fixed width and height. To achieve a scrollable list area, check the parent element Layout -> Elasticity -> Turn Elasticity off
5. What if there are too many sub-elements in some elements that cause scrollbars on the page or affect the layout of other elements?
You can try setting Advanced-> Subelement Overflow Settings-> Scrollbar, which triggers the BFC mechanism to become a stand-alone rendering area as long as it is not Set-Up, so that no overflow or impact on the layout of other elements will occur.
6. What can I do when my design crash prevents FrontendBlocks from opening?
Despite my best efforts to avoid software crashes, the reality is that the software is operating in a complex environment with unexpected BUGs. You can press F12 to delete tempSave and refresh the interface in Application->Storage->Local Storage. If not, you can copy the values in tempSave to raise a question and the community will resolve the BUG as soon as possible.
#### 二次开发说明 Secondary Development
#### 二次开发说明
1. “在内部插入”功能的扩展是在public/tools.json中完成,手动编写可以参照第4条。
2. 想要增加新的属性,可以修改src/components/layout/PropertiesPanel.vue文件,data里的defaultForm是默认值,每一次更新都会用它来初始化,当前编辑的元素样式都会存在在propForm对象里。fromBlock方法会将选中元素的样式进行解析,回显到界面上。而toBlock方法则会将填写好的属性赋予给选中元素,使之生效。(如果你需要和业务系统相结合,可以在这里加点东西,比如接口地址、数据来源之类的)
3. 生成代码的功能都放在了src/components/layout/ToolsBar.vue里,想生成其他语言的(比如Android的XML、React、甚至Winform,可以根据逻辑自行实现)
......@@ -98,26 +134,16 @@ Despite my best efforts to avoid software crashes, the reality is that the softw
5. 上下文在src/components/layout/WorkSpace.vue里,它是充血的,可以扩展方法,而且几乎在整个项目的任何地方都能找到它的引用,其中的createNewBlock定义了创建一个新元素的初始属性。
6. 总的来说,实现逻辑就是:模板创建->用户自定义属性->上下文连锁更新->Block.vue预览表达->ToolsBar.vue生成代码->CodePreview.vue预览并下载代码
#### 快捷键
1. Ctrl+C 复制选中的块
2. Ctrl+V 在所选中块的内部进行追加粘贴
3. Delete 删除选中的块
4. Ctrl+Z 撤销
1. The extension of the "insert inside" function is completed in public/tools.json. Please refer to Article 4 for manual writing.
2. To add new properties, you can modify src/components/layout/PropertiesPanel.vue file, the defaultform in the data is the default value. It will be used to initialize each update. The currently edited element style will exist in the propform object. The fromblock method will parse the style of the selected element and echo it to the interface. The toblock method will assign the filled attributes to the selected element to make it effective. (if you need to integrate with the business system, you can add something here, such as interface address, data source, etc.)
3. The function of generating code is placed in src/components/layout/ToolsBar.vue, you want to generate other languages (such as Android XML, react, and even WinForm, which can be implemented according to logic)
4. In the object corresponding to each element, properties represents the additional attribute, ID represents the globally unique code, style represents the style of the element, blocks represents the collection of sub elements of the element, domtype is the type of the element (default is div, even if expressed as view, it is also written as DIV), and text refers to the text inside the element
5. The context is in src/components/layout/WorkSpace.vue, it is congested and can be extended. Its reference can be found almost anywhere in the whole project. The createnewblock defines the initial attribute of creating a new element.
6. In general, the implementation logic is: template creation - > user-defined attributes - > context chain update - > block.vue preview expression - > toolbar.vue generate code - > codepreview.vue preview and download code
#### 快捷键 Shortcut Keys
1. Ctrl+C 复制选中的块 Copy selected block
2. Ctrl+V 在所选中块的内部进行追加粘贴 Paste copied block in selected block
3. Delete 删除选中的块 Delete selected block
4. Ctrl+Z 撤销 Undo
#### 参与贡献 Contributors
#### 参与贡献
1. 黑龙江省瑜美科技发展有限公司 杨若瑜 2020年 创建 1.0
Heilongjiang Yumeisoft Co., Ltd Ruoyu Yang in 2020 ver 1.0
1. 黑龙江省瑜美科技发展有限公司 杨若瑜 2020年 创建 1.0
#### 其他 Other
#### 其他
1. 我的博客:yangruoyu.blog.csdn.net
My Blog: yangruoyu.blog.csdn.net
1. 我的博客:yangruoyu.blog.csdn.net
此差异已折叠。
<template>
<el-dialog title="代码预览" :visible.sync="visible" width="70%" @close="onClose">
<div class="root">
<div class="codePanel">
<textarea class="codeArea">{{code}}</textarea>
</div>
<div class="buttonBar">
<div class="closeBtn" @click="onClose">关闭</div>
<div class="saveBtn" @click="onSave">保存</div>
</div>
</div>
</el-dialog>
<el-dialog title="代码预览" :visible.sync="visible" width="70%" @close="onClose">
<div class="root">
<div class="codePanel">
<textarea id="codeArea" class="codeArea" @click="copyCode">{{code}}</textarea>
</div>
<div class="buttonBar">
<div class="closeBtn" @click="onClose">关闭</div>
<div class="saveBtn" @click="onSave">保存</div>
</div>
</div>
</el-dialog>
</template>
<script>
export default {
data: () => ({
}),
props: ['visible','onClose','onSave','code'],
methods: {
},
};
export default {
data: () => ({}),
props: ['visible', 'onClose', 'onSave', 'code'],
methods: {
copyCode() {
document.getElementById("codeArea").select();
let successful = document.execCommand("copy")
if (successful) {
this.$message({
message: '复制成功!',
type: 'success'
});
}
}
},
};
</script>
<style scoped>
.root {
box-sizing: border-box;
font-weight: normal;
font-style: normal;
text-align: left;
display: flex;
position: relative;
width: 100%;
height: 600px;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
}
.codePanel {
box-sizing: border-box;
font-weight: normal;
font-style: normal;
text-align: left;
display: flex;
position: relative;
width: 100%;
height: 100%;
padding: 20px;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
}
.codeArea {
box-sizing: border-box;
font-weight: normal;
font-style: normal;
text-align: left;
display: flex;
position: relative;
width: 100%;
height: 100%;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
overflow: hidden scroll;
}
.buttonBar {
box-sizing: border-box;
border: 1px solid rgba(207, 207, 207, 1);
border-top: 1px solid rgba(207, 207, 207, 1);
border-bottom: none;
border-left: none;
border-right: none;
font-weight: normal;
font-style: normal;
text-align: left;
display: flex;
position: relative;
width: 100%;
padding: 10px;
flex-direction: row;
justify-content: space-between;
align-items: flex-end;
}
.closeBtn {
box-sizing: border-box;
background-color: rgba(159, 159, 159, 1);
border-radius: 100px;
font-weight: normal;
font-style: normal;
color: rgba(255, 255, 255, 1);
text-align: left;
display: flex;
position: relative;
width: 100%;
padding: 10px;
margin: 0px 20px 0px 0px;
flex-direction: column;
justify-content: center;
align-items: center;
}
.saveBtn {
box-sizing: border-box;
background-color: rgba(68, 125, 56, 1);
border-radius: 100px;
font-weight: normal;
font-style: normal;
color: rgba(255, 255, 255, 1);
text-align: left;
display: flex;
position: relative;
width: 100%;
padding: 10px;
flex-direction: column;
justify-content: center;
align-items: center;
}
.root {
box-sizing: border-box;
font-weight: normal;
font-style: normal;
text-align: left;
display: flex;
position: relative;
width: 100%;
height: 600px;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
}
.codePanel {
box-sizing: border-box;
font-weight: normal;
font-style: normal;
text-align: left;
display: flex;
position: relative;
width: 100%;
height: 100%;
padding: 20px;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
}
.codeArea {
box-sizing: border-box;
font-weight: normal;
font-style: normal;
text-align: left;
display: flex;
position: relative;
width: 100%;
height: 100%;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
overflow: hidden scroll;
}
.buttonBar {
box-sizing: border-box;
border: 1px solid rgba(207, 207, 207, 1);
border-top: 1px solid rgba(207, 207, 207, 1);
border-bottom: none;
border-left: none;
border-right: none;
font-weight: normal;
font-style: normal;
text-align: left;
display: flex;
position: relative;
width: 100%;
padding: 10px;
flex-direction: row;
justify-content: space-between;
align-items: flex-end;
}
.closeBtn {
box-sizing: border-box;
background-color: rgba(159, 159, 159, 1);
border-radius: 100px;
font-weight: normal;
font-style: normal;
color: rgba(255, 255, 255, 1);
text-align: left;
display: flex;
position: relative;
width: 100%;
padding: 10px;
margin: 0px 20px 0px 0px;
flex-direction: column;
justify-content: center;
align-items: center;
}
.saveBtn {
box-sizing: border-box;
background-color: rgba(68, 125, 56, 1);
border-radius: 100px;
font-weight: normal;
font-style: normal;
color: rgba(255, 255, 255, 1);
text-align: left;
display: flex;
position: relative;
width: 100%;
padding: 10px;
flex-direction: column;
justify-content: center;
align-items: center;
}
</style>
\ No newline at end of file
......@@ -17,8 +17,8 @@
<td>纯色背景</td>
<td>
<div style="display: flex;flex-direction: row;">
<el-color-picker
v-model="propForm.common.basic.background.solid" size="mini" show-alpha @change="propForm.common.basic.background.type='Solid'">
<el-color-picker color-format="hex"
v-model="propForm.common.basic.background.solid" size="mini" @change="propForm.common.basic.background.type='Solid'">
</el-color-picker>
<el-input v-model="propForm.common.basic.background.solid" size="mini" @change="propForm.common.basic.background.type='Solid'"></el-input>
</div>
......@@ -28,7 +28,7 @@
<td>文字颜色</td>
<td>
<div style="display: flex;flex-direction: row;">
<el-color-picker size="mini" show-alpha v-model="propForm.common.text.color">
<el-color-picker color-format="hex" size="mini" v-model="propForm.common.text.color">
</el-color-picker>
<el-input v-model="propForm.common.text.color" size="mini"></el-input>
</div>
......@@ -110,6 +110,10 @@
<td>背景图URL</td>
<td><input v-model="propForm.common.basic.background.url" type="text" @change="propForm.common.basic.background.type='ImageUrl'"></td>
</tr>
<tr>
<td></td>
<td><button @click="setRandomBg(propForm.common.basic.background)">设置随机占位图</button></td>
</tr>
<tr>
<td>圆角</td>
<td>
......@@ -128,7 +132,7 @@
<tr>
<td>阴影</td>
<td>
<el-color-picker v-model="propForm.common.basic.boxShadow.color" size="mini">
<el-color-picker color-format="hex" v-model="propForm.common.basic.boxShadow.color" size="mini">
</el-color-picker>
<table
v-if="propForm.common.basic.boxShadow.color!=''&&propForm.common.basic.boxShadow.color!=null"
......@@ -252,8 +256,8 @@
<option value="Cover">等比例适应</option>
</select>
<!-- 用于纯色输入 -->
<el-color-picker v-if="propForm.common.basic.background.type=='Solid'"
v-model="propForm.common.basic.background.solid" size="mini" show-alpha>
<el-color-picker color-format="hex" v-if="propForm.common.basic.background.type=='Solid'"
v-model="propForm.common.basic.background.solid" size="mini">
</el-color-picker>
<!-- 用于渐变输入 -->
<table v-if="propForm.common.basic.background.type=='Gradient'" class="propTable" border="0"
......@@ -265,12 +269,12 @@
</tr>
<tr>
<td>
<el-color-picker v-model="propForm.common.basic.background.gradient.start"
size="mini" show-alpha></el-color-picker>
<el-color-picker color-format="hex" v-model="propForm.common.basic.background.gradient.start"
size="mini"></el-color-picker>
</td>
<td>
<el-color-picker v-model="propForm.common.basic.background.gradient.end"
size="mini" show-alpha></el-color-picker>
<el-color-picker color-format="hex" v-model="propForm.common.basic.background.gradient.end"
size="mini"></el-color-picker>
</td>
<td>
<el-input v-model="propForm.common.basic.background.gradient.angle"
......@@ -285,7 +289,7 @@
border="0" cellspacing="" cellpadding="">
<tr>
<td><button @click="()=>{
$message('还没实现该功能')
$message('还没实现该功能,需要你自己集成后端图片上传接口')
}">立即上传</button></td>
</tr>
</table>
......@@ -305,7 +309,7 @@
<tr>
<td>阴影</td>
<td>
<el-color-picker v-model="propForm.common.basic.boxShadow.color" size="mini">
<el-color-picker color-format="hex" v-model="propForm.common.basic.boxShadow.color" size="mini">
</el-color-picker>
<table
v-if="propForm.common.basic.boxShadow.color!=''&&propForm.common.basic.boxShadow.color!=null"
......@@ -426,7 +430,7 @@
<tr v-if="propForm.common.border.width>0">
<td>颜色</td>
<td>
<el-color-picker size="mini" show-alpha v-model="propForm.common.border.color"
<el-color-picker color-format="hex" size="mini" v-model="propForm.common.border.color"
@change="borderChange">
</el-color-picker>
</td>
......@@ -465,7 +469,7 @@
<tr>
<td>颜色</td>
<td>
<el-color-picker size="mini" show-alpha v-model="propForm.common.text.color">
<el-color-picker color-format="hex" size="mini" v-model="propForm.common.text.color">
</el-color-picker>
</td>
</tr>
......@@ -1584,6 +1588,10 @@
// }
block.style = style;
},
setRandomBg(target){
this.propForm.common.basic.background.url="https://source.unsplash.com/random/?t="+Math.random()
this.propForm.common.basic.background.type='ImageUrl'
},
borderChange() {
let border = this.propForm.common.border
let origin = {
......
此差异已折叠。
......@@ -103,7 +103,10 @@
if (!parent) {
throw '必须要传入对象'
}
parent.id = "block-" + (++context.tabBlocks[context.currentTab].indexCounter)
// 避免重复
if(this.findBlockById(parent.id)){
parent.id = "block-" + (++context.tabBlocks[context.currentTab].indexCounter)
}
for (let i in parent.blocks) {
let child = parent.blocks[i]
context.autoRenameNewBlocks(child)
......
let cssCache = {}
let cssParentCache = {}
let jsCache = {}
let imgTagName="img"
function genCssContent(block, unitRate, unitName, parentBlock) {
let css = '';
for (let key in block.style) {
let value = new String(block.style[key])
// 处理RPX换算问题
if (value) {
let allCells = value.split(' ')
for (let i = 0; i < allCells.length; i++) {
if (allCells[i].match('[0-9]+px')) {
allCells[i] = (parseInt(allCells[i].replace('px', '')) * unitRate) + unitName
}
}
value = allCells.join(' ')
}
let realCss = key.replace(/([A-Z])/g, "-$1").toLowerCase()
// 过滤一些不需要的
if (realCss == 'font-weight' && value == 'normal') continue
if (realCss == 'font-style' && value == 'normal') continue
// 过滤无子元素的样式
if (!(block.blocks && (block.blocks.length > 0 || block.text != null))) {
if (realCss == 'display' && value == 'flex') continue
if (realCss == 'position' && value == 'relative') continue
if (realCss == 'width' && value == '100%' && block.domType == 'div' && parentBlock != null &&
parentBlock.blocks.length > 1) continue
if (realCss == 'flex-direction') continue
if (realCss == 'justify-content') continue
if (realCss == 'align-items') continue
}
// 过滤Flex布局的默认值
if (realCss == 'flex-direction' && value == 'row') continue
if (realCss == 'justify-content' && value == 'flex-start') continue
if (realCss == 'align-items' && value == 'flex-start') continue
// 没有边框和padding就无需加上box-sizing
if (!(block.style.border ||
block.style.borderBottom ||
block.style.borderLeft ||
block.style.borderRight ||
block.style.borderTop ||
block.style.padding ||
block.style.paddingTop ||
block.style.paddingLeft ||
block.style.paddingRight ||
block.style.paddingBottom)) {
if (realCss == 'box-sizing' && value == 'border-box') continue
}
if (realCss == 'border-top' && value == 'none') continue
if (realCss == 'border-left' && value == 'none') continue
if (realCss == 'border-right' && value == 'none') continue
if (realCss == 'border-bottom' && value == 'none') continue
if (realCss == 'border') {
if (
block.style.borderBottom == 'none' ||
block.style.borderLeft == 'none' ||
block.style.borderRight == 'none' ||
block.style.borderTop == 'none'
) {
continue
}
}
if (value.indexOf('null') != -1) continue
// 添加到结果中
css += `\t\t${realCss}:${value};\n`
}
return css;
}
function genCssMapWithChildren(block, unitRate, unitName, parentBlock, xpath) {
let result = xpath + "\n" + genCssContent(block, unitRate, unitName, parentBlock)
for (let i in block.blocks) {
result += `${xpath}>${i}\n`;
result += genCssContent(block.blocks[i], unitRate, unitName, block, xpath + ">" + i)
}
return result
}
function handleCss(block, unitRate, unitName, parentBlock, css, cssName, parentName, parentCssPath, result) {
// 样式
css = genCssContent(block, unitRate, unitName, parentBlock);
let cssMap = ''
// css合并缓存
if (css != '') {
// 递归获取包括当前CSS和所有子CSS,构筑成Key
cssMap = genCssMapWithChildren(block, unitRate, unitName, parentBlock, "self")
if (cssCache[cssMap]&&cssParentCache[cssCache[cssMap]]&&cssParentCache[cssCache[cssMap]] == parentCssPath) {
block.id = cssCache[cssMap]
css = ''
}
}
// 处理cssName
cssName = block.id
let currentCssPath = `.${block.id}`
if (block.id.startsWith(parentName)) {
cssName = block.id.substr(parentName.length + 1)
currentCssPath = `${parentCssPath}>.${cssName}`
}
// 完成CSS的添加
if (css != '') {
result.css += `\t${currentCssPath}{\n` + css + `\t}`;
if ((block.id.endsWith('-button') || block.id.endsWith('-btn'))) {
result.css += `\n\t${currentCssPath}{\n\t\tuser-select: none;\n\t}`;
result.css += `\n\t${currentCssPath}:hover{\n\t\topacity: 0.8;\n\t}`;
result.css += `\n\t${currentCssPath}:active{\n\t\topacity: 0.5;\n\t}`;
}
}
// 将CSS缓存起来,用来合并CSS
if (css != '' && cssMap != '') {
cssParentCache[block.id] = parentCssPath
cssCache[cssMap] = block.id
}
return {css, cssName, currentCssPath};
}
/**
* 转换为vue代码
* {
* // BLOCK对象
* block,
* defaultTag: 'view',
* stylesUnit: {
* name: 'rpx',
* rate: 2
* },
* clickEvent: 'tap'
* }
*/
let parse = (config) => {
// 读取生成参数
let {
block,
level,
defaultTag,
parentName,
parentCssPath,
clickEvent,
parentBlock
} = config;
if (!config.stylesUnit) {
config.stylesUnit = {
name: 'px',
rate: 1
}
}
let unitName = config.stylesUnit.name
let unitRate = config.stylesUnit.rate
if (!level) {
level = 1
}
if (level == 1) {
cssCache = {}
cssParentCache = {}
jsCache = {}
// 深拷贝
block = JSON.parse(JSON.stringify(block))
}
let result = {
html: '',
css: '',
js: ''
}
let html = ''
let js = ''
let {css, cssName, currentCssPath} =
handleCss(block, unitRate, unitName, parentBlock, '', '', parentName, parentCssPath, result);
/* 事件处理部分 */
// 获取驼峰式Id
let camelCaseId = block.id.toLowerCase().replace(/-(\w)/g, (match, p1) => p1.toUpperCase())
// 处理按钮,先看CSS,如果CSS为空,那一定是不需要加事件
if (css != '') {
if ((block.id.endsWith('-button') || block.id.endsWith('-btn'))) {
result.js +=
`\tfunction ${camelCaseId}Click(){\n\t\talert("已触发${camelCaseId}Click事件")\n\t}`
}
}
// 合并相似的事件
if (result.js) {
jsCache[block.id] = result.js
}
if (jsCache[block.id]) {
js = jsCache[block.id]
}
/* DOM组件生成 */
// 处理组件类型转换
let targetDomType = block.domType
if (block.domType) {
if (block.domType == 'div') {
targetDomType = defaultTag
} else if (block.domType == 'img') {
targetDomType = imgTagName
} else {
targetDomType = block.domType
}
} else {
targetDomType = defaultTag
}
// 处理缩进
for (let i = 0; i < level; i++) html += '\t'
// 标签开始
html +=
`<${targetDomType} class="${cssName}"`
if (js) html += ` onclick="${camelCaseId}Click()"`
if (block.domType && block.domType == 'input' && block.text) html += ` value="${block.text}"`
if (block.domType == 'input' || block.domType == 'img' || block.domType == imgTagName) {
html += '/>'
} else {
html += '>'
}
// 内容
if (block.text && (!block.domType || block.domType != 'input')) {
if (block.blocks && block.blocks.length >= 1) {
html += '\n'
for (let i = 0; i < level + 1; i++) {
html += '\t'
}
}
html += block.text
}
if (block.blocks && block.blocks.length >= 1) {
html += '\n'
for (let i = 0; i < block.blocks.length; i++) {
let child = block.blocks[i]
let childHtml = parse({
...config,
block: child,
level: level + 1,
parentName: block.id,
parentCssPath: currentCssPath,
parentBlock: block,
})
html += childHtml.html
// 顺带处理CSS
if (childHtml.css != '') {
result.css += '\n' + childHtml.css
}
if (childHtml.js != '') {
if (result.js == '') {
result.js = childHtml.js
} else {
result.js += '\n' + childHtml.js
}
}
if (i != block.blocks.length - 1) {
html += '\n'
}
}
html += '\n'
for (let i = 0; i < level; i++) {
html += '\t'
}
}
if (!(block.domType == 'input' || block.domType == 'img' || block.domType == imgTagName)) {
html += `</${targetDomType}>`
}
// 尾部
if (block.id == 'root') {
let outputFile = ""
outputFile += "<!DOCTYPE html>\n" + "<html lang=\"zhCN\">\n"
+ "<head>\n"
+"\t<meta charset=\"UTF-8\">\n\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n"
+ "\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
+ "\t<title>Document</title>\n"
+ "</head>\n"
+ "<body>\n"
outputFile += `${html}\n`
outputFile += "\t<script>\n"
outputFile += result.js
outputFile += "\n\t</" + "script>\n\n"
outputFile += "\t<style>\n"
outputFile += `\thtml,body,.root{\n`
outputFile += `\t\tpadding:0;\n`
outputFile += `\t\tmargin:0;\n`
outputFile += `\t\twidth:100%;\n`
outputFile += `\t\theight:100%;\n`
outputFile += `\t}\n`
outputFile += `\tinput{\n`
outputFile += `\t\toutline:none;\n`
outputFile += `\t\tborder:none;\n`
outputFile += `\t}\n`
outputFile += result.css + "\n"
outputFile += "\t</style>\n"
outputFile += "</body>\n"
outputFile += "</html>"
html = outputFile
}
result.html = html
return result
}
export default parse
\ No newline at end of file
let cssCache = {}
let cssParentCache = {}
let jsCache = {}
let imgTagName="image"
function genCssContent(block, unitRate, unitName, parentBlock) {
let css = '';
for (let key in block.style) {
let value = new String(block.style[key])
// 处理RPX换算问题
if (value) {
let allCells = value.split(' ')
for (let i = 0; i < allCells.length; i++) {
if (allCells[i].match('[0-9]+px')) {
allCells[i] = (parseInt(allCells[i].replace('px', '')) * unitRate) + unitName
}
}
value = allCells.join(' ')
}
let realCss = key.replace(/([A-Z])/g, "-$1").toLowerCase()
// 过滤一些不需要的
if (realCss == 'font-weight' && value == 'normal') continue
if (realCss == 'font-style' && value == 'normal') continue
// 过滤无子元素的样式
if (!(block.blocks && (block.blocks.length > 0 || block.text != null))) {
if (realCss == 'display' && value == 'flex') continue
if (realCss == 'position' && value == 'relative') continue
if (realCss == 'width' && value == '100%' && block.domType == 'div' && parentBlock != null &&
parentBlock.blocks.length > 1) continue
if (realCss == 'flex-direction') continue
if (realCss == 'justify-content') continue
if (realCss == 'align-items') continue
}
// 过滤Flex布局的默认值
if (realCss == 'flex-direction' && value == 'row') continue
if (realCss == 'justify-content' && value == 'flex-start') continue
if (realCss == 'align-items' && value == 'flex-start') continue
// 没有边框和padding就无需加上box-sizing
if (!(block.style.border ||
block.style.borderBottom ||
block.style.borderLeft ||
block.style.borderRight ||
block.style.borderTop ||
block.style.padding ||
block.style.paddingTop ||
block.style.paddingLeft ||
block.style.paddingRight ||
block.style.paddingBottom)) {
if (realCss == 'box-sizing' && value == 'border-box') continue
}
if (realCss == 'border-top' && value == 'none') continue
if (realCss == 'border-left' && value == 'none') continue
if (realCss == 'border-right' && value == 'none') continue
if (realCss == 'border-bottom' && value == 'none') continue
if (realCss == 'border') {
if (
block.style.borderBottom == 'none' ||
block.style.borderLeft == 'none' ||
block.style.borderRight == 'none' ||
block.style.borderTop == 'none'
) {
continue
}
}
if (value.indexOf('null') != -1) continue
// 添加到结果中
css += `\t\t${realCss}:${value};\n`
}
return css;
}
function genCssMapWithChildren(block, unitRate, unitName, parentBlock, xpath) {
let result = xpath + "\n" + genCssContent(block, unitRate, unitName, parentBlock)
for (let i in block.blocks) {
result += `${xpath}>${i}\n`;
result += genCssContent(block.blocks[i], unitRate, unitName, block, xpath + ">" + i)
}
return result
}
function handleCss(block, unitRate, unitName, parentBlock, css, cssName, parentName, parentCssPath, result) {
// 样式
css = genCssContent(block, unitRate, unitName, parentBlock);
let cssMap = ''
// css合并缓存
if (css != '') {
// 递归获取包括当前CSS和所有子CSS,构筑成Key
cssMap = genCssMapWithChildren(block, unitRate, unitName, parentBlock, "self")
if (cssCache[cssMap]&&cssParentCache[cssCache[cssMap]]&&cssParentCache[cssCache[cssMap]] == parentCssPath) {
block.id = cssCache[cssMap]
css = ''
}
}
// 处理cssName
cssName = block.id
let currentCssPath = `.${block.id}`
if (block.id.startsWith(parentName)) {
cssName = block.id.substr(parentName.length + 1)
currentCssPath = `${parentCssPath}>.${cssName}`
}
// 完成CSS的添加
if (css != '') {
result.css += `\t${currentCssPath}{\n` + css + `\t}`;
if ((block.id.endsWith('-button') || block.id.endsWith('-btn'))) {
result.css += `\n\t${currentCssPath}:hover{\n\t\topacity: 0.8;\n\t}`;
result.css += `\n\t${currentCssPath}:active{\n\t\topacity: 0.5;\n\t}`;
}
}
// 将CSS缓存起来,用来合并CSS
if (css != '' && cssMap != '') {
cssParentCache[block.id] = parentCssPath
cssCache[cssMap] = block.id
}
return {css, cssName, currentCssPath};
}
/**
* 转换为vue代码
* {
* // BLOCK对象
* block,
* defaultTag: 'view',
* stylesUnit: {
* name: 'rpx',
* rate: 2
* },
* clickEvent: 'tap'
* }
*/
let parse = (config) => {
// 读取生成参数
let {
block,
level,
defaultTag,
parentName,
parentCssPath,
clickEvent,
parentBlock
} = config;
if (!config.stylesUnit) {
config.stylesUnit = {
name: 'px',
rate: 1
}
}
let unitName = config.stylesUnit.name
let unitRate = config.stylesUnit.rate
if (!level) {
level = 1
}
if (level == 1) {
cssCache = {}
cssParentCache = {}
jsCache = {}
// 深拷贝
block = JSON.parse(JSON.stringify(block))
}
let result = {
html: '',
css: '',
js: ''
}
let html = ''
let js = ''
let {css, cssName, currentCssPath} =
handleCss(block, unitRate, unitName, parentBlock, '', '', parentName, parentCssPath, result);
/* 事件处理部分 */
// 获取驼峰式Id
let camelCaseId = block.id.toLowerCase().replace(/-(\w)/g, (match, p1) => p1.toUpperCase())
// 处理按钮,先看CSS,如果CSS为空,那一定是不需要加事件
if (css != '') {
if ((block.id.endsWith('-button') || block.id.endsWith('-btn'))) {
result.js +=
`\t\t\t${camelCaseId}Click(){\n\t\t\t\tuni.showToast({\n\t\t\t\t\ttitle: '已触发${camelCaseId}Click事件',\n\t\t\t\t\ticon: 'none',\n\t\t\t\t\tduration: 2000\n\t\t\t\t})\n\t\t\t},`
}
}
// 合并相似的事件
if (result.js) {
jsCache[block.id] = result.js
}
if (jsCache[block.id]) {
js = jsCache[block.id]
}
/* DOM组件生成 */
// 处理组件类型转换
let targetDomType = block.domType
if (block.domType) {
if (block.domType == 'div') {
targetDomType = defaultTag
} else if (block.domType == 'img') {
targetDomType = imgTagName
} else {
targetDomType = block.domType
}
} else {
targetDomType = defaultTag
}
// 处理缩进
for (let i = 0; i < level; i++) html += '\t'
// 标签开始
html +=
`<${targetDomType} class="${cssName}"`
if (js) html += ` @${clickEvent}="${camelCaseId}Click"`
if (block.domType && block.domType == 'input' && block.text) html += ` value="${block.text}"`
if (block.domType == 'input' || block.domType == 'img' || block.domType == imgTagName) {
html += '/>'
} else {
html += '>'
}
// 内容
if (block.text && (!block.domType || block.domType != 'input')) {
if (block.blocks && block.blocks.length >= 1) {
html += '\n'
for (let i = 0; i < level + 1; i++) {
html += '\t'
}
}
html += block.text
}
if (block.blocks && block.blocks.length >= 1) {
html += '\n'
for (let i = 0; i < block.blocks.length; i++) {
let child = block.blocks[i]
let childHtml = parse({
...config,
block: child,
level: level + 1,
parentName: block.id,
parentCssPath: currentCssPath,
parentBlock: block,
})
html += childHtml.html
// 顺带处理CSS
if (childHtml.css != '') {
result.css += '\n' + childHtml.css
}
if (childHtml.js != '') {
if (result.js == '') {
result.js = childHtml.js
} else {
result.js += '\n' + childHtml.js
}
}
if (i != block.blocks.length - 1) {
html += '\n'
}
}
html += '\n'
for (let i = 0; i < level; i++) {
html += '\t'
}
}
if (!(block.domType == 'input' || block.domType == 'img' || block.domType == imgTagName)) {
html += `</${targetDomType}>`
}
// 尾部
if (block.id == 'root') {
let outputFile = ""
outputFile += `<template>\n${html}\n`
outputFile += "</template>\n\n"
outputFile += "<script>\n"
outputFile += "\texport default {\n"
outputFile += "\t\tdata: () => ({}),\n"
outputFile += "\t\tprops:[],\n"
outputFile += "\t\tmethods:{\n" + result.js + "\n\t\t},\n"
outputFile += "\t\t// 组件生命周期钩子\n"
outputFile += "\t\tbeforeCreate() {},\n"
outputFile += "\t\tcreated() {},\n"
outputFile += "\t\tbeforeMount() {},\n"
outputFile += "\t\tmounted() {},\n"
outputFile += "\t\tbeforeUpdate() {},\n"
outputFile += "\t\tupdated() {},\n"
outputFile += "\t\tbeforeDestroy() {},\n"
outputFile += "\t\tdestroyed() {},\n"
outputFile += "\t\t// Uniapp页面生命周期钩子\n"
outputFile += "\t\tonPullDownRefresh() {\n\t\t\tuni.stopPullDownRefresh()\n\t\t},\n"
outputFile += "\t\tonLoad(options) {},\n"
outputFile += "\t\tonShow() {},\n"
outputFile += "\t\tonReady() {},\n"
outputFile += "\t\tonHide() {},\n"
outputFile += "\t\tonUnload() {},\n"
outputFile += "\t\tonBackPress() {},\n"
outputFile += "\t\tonReachBottom() {},\n"
outputFile += "\t\tonTabItemTap(index,pagePath,text) {},\n"
outputFile += "\t\tonNavigationBarButtonTap(index) {},\n"
outputFile += "\t}\n"
outputFile += "</" + "script>\n\n"
outputFile += "<style scoped>\n"
outputFile += `\thtml,body,.root,uni-page-body,page #app{\n`
outputFile += `\t\tpadding:0;\n`
outputFile += `\t\tmargin:0;\n`
outputFile += `\t\twidth:100%;\n`
outputFile += `\t\theight:100%;\n`
outputFile += `\t}\n`
outputFile += result.css + "\n"
outputFile += "</style>"
html = outputFile
}
result.html = html
return result
}
export default parse
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册