Commit cd867a2b authored by JingChao's avatar JingChao

layout

parent e895f1e7
...@@ -532,6 +532,9 @@ showActionSheetButton() { ...@@ -532,6 +532,9 @@ showActionSheetButton() {
``` ```
### Note ### Note
hls-easy-ui#0.0.5
[添加动态配置组件 h-layout](/packages/components/HLayout/README.md)
hls-easy-ui#0.0.4 hls-easy-ui#0.0.4
[添加懒加载组建](https://github.com/hilongjw/vue-lazyload) [添加懒加载组建](https://github.com/hilongjw/vue-lazyload)
......
动态配置功能
目前支持配置 form、s-tab、button 以及底部固定位置的按钮
```html
/**
* @Author think
* @Date 2019-07-16 20:00
*/
<template>
<h-view class="form">
<h-header>
<div slot="left" class="h-header-btn" @click="$hlsExit()">
<i class="ion-ios-arrow-back"/>
</div>
<div slot="center">From</div>
<div slot="right" class="h-header-btn">右边</div>
</h-header>
<h-layout
v-if="layoutShow"
:layout-data="layoutData" :show-form-title="showFormTitle" :show-btn-divider="true"
:show-tab-divider="true" :formData="data" v-model="data" @tabClick="tabClick"
@showSelect="showSelect" @showTime="showTime" @switchClick="switchClick" @filedClick="filedClick"
@btnClick="btnClick"/>
</h-view>
</template>
```
```javascript
<script>
import layoutData from './layout.json'
export default {
name: 'Form',
data () {
return {
tabIndex: 1,
showFormTitle: true,
layoutData: [],
layoutShow: false,
data: {
contract: {
postion: '01',
postion_n: '技术顾问',
enable_flag: false,
},
},
postionList: [
{code: '01', code_name: '技术顾问'},
{code: '02', code_name: '技术经理'},
{code: '03', code_name: '项目经理'},
],
}
},
created () {
let vm = this
/* axios.get('http://leafservice.hand-china.com/r/api/get/layoutCode?layoutCode=CON_QURERY', {
header: {'Content-Type': 'application/json',
'Authorization': 'bearer SRHJVdrftyGUYguyhiHiuiojmgrrcgv' },
}).then(res => {
vm.layoutData = res.rows
vm.layoutShow = true
}) */
setTimeout(() => {
vm.layoutData = layoutData
vm.layoutShow = true
}, 100)
},
methods: {
/**
* tab的点击事件
* @param index
*/
tabClick (index) {
this.tabIndex = index
},
showPostion (configCode, filedCode) {
let vm = this
vm.hlsPopup.selectList({
list: vm.postionList,
code: filedCode,
object: vm.data[configCode],
returnItem (index) {
vm.data[configCode][filedCode] = vm.postionList[index].code
vm.data[configCode][filedCode + '_n'] = vm.postionList[index].code_name
},
})
},
/**
* 下拉框点击事件
* @param configCode
* @param filedCode
*/
showSelect (configCode, filedCode) {
let vm = this
switch (filedCode) {
case 'postion':
vm.showPostion(configCode, filedCode)
break
default:
}
},
showOrderDate (configCode, filedCode) {
let vm = this
vm.hlsPopup.showTime({
callback (time) {
vm.data[configCode][filedCode] = time
},
})
},
/**
* 事件选择事件
* @param configCode
* @param filedCode
*/
showTime (configCode, filedCode) {
let vm = this
switch (filedCode) {
case 'order_date':
vm.showOrderDate(configCode, filedCode)
break
default:
}
},
/**
* switch的点开事件
* @param configCode
* @param filedCode
* @param value
*/
switchClick (configCode, filedCode, value) {
debugger
},
/**
* 其他字端的点击事件
* @param configCode
* @param filedCode
*/
filedClick (configCode, filedCode) {
debugger
},
/**
* 按钮点击事件
* @param btn
*/
btnClick (btn) {
console.log(JSON.stringify(this.data, '', 2))
if (btn.btnType === 'BottomTab') {
if (btn.btnCode === 'save') {
alert('底部固定按钮的保存')
}
if (btn.btnCode === 'submit') {
alert('底部固定按钮的提交')
}
} if (btn.btnType === 'Button') {
if (btn.btnCode === 'nextBtn') {
alert('按钮继续')
}
}
},
},
}
</script>
```
```less
<style lang="less">
.form {
}
</style>
```
1. 动态布局目前仅仅支持一个 s-tab组件,一个底部按钮bottom-tab 组件
2. 组件名为h-layout,需要在布局查询出来之后再去渲染此组件否则渲染失败
3. 布局的查询在created生命周期函数内查询,查询成功再去渲染组件
4. 应无法在data里面直接set数据,故需在data里面新建data数据对象用于组件解析成功以及数据双向绑定使用
5. 支持在自定义data对象设置默认值,默认值的优先级高于组件定义的默认值
6. 组件使用v-model与formData进行传递data数据实现双向绑定,两者缺一不可
7. 组件中会解析出全部的按钮,每个按钮对应 组件code、按钮code、以及按钮描述。已btns数组反馈给父组件,用于按钮点击事件
8. 所有的下拉框、时间以及按钮的触发逻辑全部交由父组件处理,子组件通知父组件,子组件内不做任何业务处理逻辑
props
* layoutData:组件布局默认数组
* showFormTitle:是否展示form表单上的title,title也可以点击实现form的缩放 默认 true
* showTabDivider:是否显示s-tab的分割线 默认true
* showTabBorder:是否显示s-tab的下边框 默认false
* showBtnDivider:是否底部按钮的分割线 默认true
* formData:组件数据,用于双向绑定
emit
* tabClick s-tab组件切换点击事件 返回当前点击的index
* showSelect 下拉框点开事件 返回布局组件code,字端的code,用于判断是哪个下拉框
* showTime 事件点开事件 返回组件code,字端的code,用于判断是哪个时间选择
* switchClick switch切换开关点击事件,返回组件code,字端的code以及value值
* filedClick 其它字端点击事件,字端类型为其它的点击事件 返回组件code,字端的code,可用于超链接,提示等
* btnClick 按钮点击事件,返回当前btn对象,包含组件code、按钮code、以及按钮描述,可根据此判断点击的是哪个按钮
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<template> <template>
<section class="h-form"> <section class="h-form">
<s-tab <s-tab
v-for="com in layoutConfig" v-if="com.configType==='TAB' && com.layoutFiledList.length" v-for="com in layoutConfig" v-if="com.configType==='Stab' && com.layoutFiledList.length"
:key="com.configId" :key="com.configId"
:default-active="tabIndex" :class="com.cssClass" :has-border="showTabBorder" :default-active="tabIndex" :class="com.cssClass" :has-border="showTabBorder"
:show-divider="showTabDivider" :show-divider="showTabDivider"
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<h-content :class="{'has-footer':hasBottom}"> <h-content :class="{'has-footer':hasBottom}">
<template v-for="(com, index) in layoutConfig"> <template v-for="(com, index) in layoutConfig">
<list-item <list-item
v-if="com.configType==='FORM' && com.layoutFiledList.length" v-show="checkFromHide(com)" v-if="com.configType==='Form' && com.layoutFiledList.length" v-show="checkFromHide(com)"
:class="com.cssClass" :key="com.configId"> :class="com.cssClass" :key="com.configId">
<item v-show="showFormTitle" class="form-title" @click.native="hideFormClick(index)"> <item v-show="showFormTitle" class="form-title" @click.native="hideFormClick(index)">
<div slot="name">{{ com.configName }}</div> <div slot="name">{{ com.configName }}</div>
...@@ -58,17 +58,17 @@ ...@@ -58,17 +58,17 @@
<img v-if="filed.rightIcon" slot="right-icon" :src="filed.rightIcon" class="right-icon"> <img v-if="filed.rightIcon" slot="right-icon" :src="filed.rightIcon" class="right-icon">
</item> </item>
</list-item> </list-item>
<template v-else-if="com.configType==='BUTTON' && com.layoutFiledList.length"> <section v-else-if="com.configType==='Button' && com.layoutFiledList.length" class="layout-button">
<h-button <h-button
v-for="btn in com.layoutFiledList" :key="btn.filedId" :class="btn.cssClass" v-for="btn in com.layoutFiledList" :key="btn.filedId" :class="btn.cssClass"
size="normal" @click.native="btnClick(com,btn)"> size="normal" @click.native="btnClick(com,btn)">
<section v-html="btn.btnContent || btn.filedName"/> <section v-html="btn.btnContent || btn.filedName"/>
</h-button> </h-button>
</template> </section>
</template> </template>
</h-content> </h-content>
<bottom-tab <bottom-tab
v-for="(com, index) in layoutConfig" v-if="com.configType==='bottomTab' && com.layoutFiledList.length" v-for="(com, index) in layoutConfig" v-if="com.configType==='BottomTab' && com.layoutFiledList.length"
:key="index" :show-divider="showBtnDivider" :key="index" :show-divider="showBtnDivider"
:class="com.cssClass"> :class="com.cssClass">
<tab-button v-for="btn in com.layoutFiledList" :key="btn.filedId" :class="btn.cssClass" @click.native="btnClick(com,btn)"> <tab-button v-for="btn in com.layoutFiledList" :key="btn.filedId" :class="btn.cssClass" @click.native="btnClick(com,btn)">
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
</template> </template>
<script> <script>
export default { export default {
name: 'HForm', name: 'HLayout',
props: { props: {
layoutData: { layoutData: {
type: Array, type: Array,
...@@ -91,7 +91,7 @@ export default { ...@@ -91,7 +91,7 @@ export default {
}, },
showTabDivider: { showTabDivider: {
type: Boolean, type: Boolean,
default: false, default: true,
}, },
showTabBorder: { showTabBorder: {
type: Boolean, type: Boolean,
...@@ -130,10 +130,10 @@ export default { ...@@ -130,10 +130,10 @@ export default {
vm.layoutConfig = vm.layoutData[0].layoutConfigList vm.layoutConfig = vm.layoutData[0].layoutConfigList
let btns = [] let btns = []
vm.layoutConfig.forEach((com, index) => { vm.layoutConfig.forEach((com, index) => {
if (com.configType === 'bottomTab') { if (com.configType === 'BottomTab') {
vm.hasBottom = true vm.hasBottom = true
} }
if (com.configType === 'FORM') { if (com.configType === 'Form') {
let form = com let form = com
let temp = {} let temp = {}
if (form.layoutFiledList.length) { if (form.layoutFiledList.length) {
...@@ -157,10 +157,10 @@ export default { ...@@ -157,10 +157,10 @@ export default {
}) })
vm.$set(vm.data, [form.configCode], temp) vm.$set(vm.data, [form.configCode], temp)
} }
} else if (com.configType === 'TAB') { } else if (com.configType === 'Stab') {
vm.activeTab = com.configCode vm.activeTab = com.configCode
vm.activeTabFiled = com.layoutFiledList.length ? com.layoutFiledList[vm.tabIndex].filedCode : '' vm.activeTabFiled = com.layoutFiledList.length ? com.layoutFiledList[vm.tabIndex].filedCode : ''
} else if (com.configType === 'BUTTON' || com.configType === 'bottomTab') { } else if (com.configType === 'Button' || com.configType === 'BottomTab') {
if (com.layoutFiledList.length) { if (com.layoutFiledList.length) {
let btnFileds = com.layoutFiledList let btnFileds = com.layoutFiledList
btnFileds.forEach((btnFiled, index) => { btnFileds.forEach((btnFiled, index) => {
...@@ -267,7 +267,7 @@ export default { ...@@ -267,7 +267,7 @@ export default {
* @param filed 当前字端 * @param filed 当前字端
*/ */
btnClick (com, filed) { btnClick (com, filed) {
let btnType = com.configCode let btnType = com.configType
let btnCode = filed.filedCode let btnCode = filed.filedCode
this.data.btns.forEach((btn, index) => { this.data.btns.forEach((btn, index) => {
if (btn.btnType === btnType && btn.btnCode === btnCode) { if (btn.btnType === btnType && btn.btnCode === btnCode) {
...@@ -302,6 +302,19 @@ export default { ...@@ -302,6 +302,19 @@ export default {
} }
} }
} }
.layout-button{
margin-top: 30px;
display: flex;
justify-content: center;
.hls-h-button{
width: 50%;
border-radius: 20px;
background-color:@theme-color;
border: none;
color: #fff;
}
}
.hls-item { .hls-item {
.contents { .contents {
......
...@@ -26,7 +26,7 @@ import HFile from './HFile/index' ...@@ -26,7 +26,7 @@ import HFile from './HFile/index'
import BottomTab from './BottomTab/index' import BottomTab from './BottomTab/index'
import TabButton from './BottomTab/tab-button' import TabButton from './BottomTab/tab-button'
import Modal from './Modal/Modal' import Modal from './Modal/Modal'
import HForm from './HForm/index' import HLayout from './HLayout/index'
import errLoadingPic from '../common/picture/errloading.jpg' import errLoadingPic from '../common/picture/errloading.jpg'
...@@ -58,5 +58,5 @@ export default (Vue) => { ...@@ -58,5 +58,5 @@ export default (Vue) => {
Vue.component('radio-group', RadioGroup) Vue.component('radio-group', RadioGroup)
Vue.component('h-radio', Radio) Vue.component('h-radio', Radio)
Vue.component('h-file', HFile) Vue.component('h-file', HFile)
Vue.component('h-form', HForm) Vue.component('h-layout', HLayout)
} }
...@@ -23,7 +23,7 @@ import Stab from './components/STab/index' ...@@ -23,7 +23,7 @@ import Stab from './components/STab/index'
import TabItem from './components/STab/tab-item' import TabItem from './components/STab/tab-item'
import TabButton from './components/BottomTab/tab-button' import TabButton from './components/BottomTab/tab-button'
import HFile from './components/HFile/index' import HFile from './components/HFile/index'
import HForm from './components/HForm/index' import HLayout from './components/HLayout/index'
import componentInstall from './components/component' import componentInstall from './components/component'
// compontenPlugins // compontenPlugins
...@@ -65,7 +65,7 @@ export { ...@@ -65,7 +65,7 @@ export {
BottomTab, BottomTab,
TabButton, TabButton,
HFile, HFile,
HForm, HLayout,
ActionSheetPlugin, ActionSheetPlugin,
ShowPicturePlugin, ShowPicturePlugin,
SelectPlugin, SelectPlugin,
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// (runtime-only or standalone) has been set in webpack.base.conf with an alias. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue' import Vue from 'vue'
import FastClick from 'fastclick' import FastClick from 'fastclick'
import axios from 'axios'
import App from './App' import App from './App'
import router from './router/index' import router from './router/index'
...@@ -48,6 +49,7 @@ Vue.use(filter) ...@@ -48,6 +49,7 @@ Vue.use(filter)
Vue.prototype.hlsPopup = window.hlsPopup = hlsPopup Vue.prototype.hlsPopup = window.hlsPopup = hlsPopup
Vue.prototype.$devicePixelRatio = 2 Vue.prototype.$devicePixelRatio = 2
Vue.prototype.axios = window.axios = axios
Vue.prototype.$post = post Vue.prototype.$post = post
Vue.prototype.$get = get Vue.prototype.$get = get
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
<div slot="center">From</div> <div slot="center">From</div>
<div slot="right" class="h-header-btn">右边</div> <div slot="right" class="h-header-btn">右边</div>
</h-header> </h-header>
<h-form <h-layout
v-if="layoutShow"
:layout-data="layoutData" :show-form-title="showFormTitle" :show-btn-divider="true" :layout-data="layoutData" :show-form-title="showFormTitle" :show-btn-divider="true"
:show-tab-divider="true" :formData="data" v-model="data" @tabClick="tabClick" :show-tab-divider="true" :formData="data" v-model="data" @tabClick="tabClick"
@showSelect="showSelect" @showTime="showTime" @switchClick="switchClick" @filedClick="filedClick" @showSelect="showSelect" @showTime="showTime" @switchClick="switchClick" @filedClick="filedClick"
...@@ -30,7 +31,8 @@ export default { ...@@ -30,7 +31,8 @@ export default {
return { return {
tabIndex: 1, tabIndex: 1,
showFormTitle: true, showFormTitle: true,
layoutData: [...layoutData], layoutData: [],
layoutShow: false,
data: { data: {
contract: { contract: {
postion: '01', postion: '01',
...@@ -46,7 +48,19 @@ export default { ...@@ -46,7 +48,19 @@ export default {
} }
}, },
created () { created () {
let vm = this
/* axios.get('http://leafservice.hand-china.com/r/api/get/layoutCode?layoutCode=CON_QURERY', {
header: {'Content-Type': 'application/json',
'Authorization': 'bearer SRHJVdrftyGUYguyhiHiuiojmgrrcgv' },
}).then(res => {
vm.layoutData = res.rows
vm.layoutShow = true
}) */
setTimeout(() => {
vm.layoutData = layoutData
vm.layoutShow = true
}, 100)
}, },
methods: { methods: {
/** /**
...@@ -126,7 +140,19 @@ export default { ...@@ -126,7 +140,19 @@ export default {
* @param btn * @param btn
*/ */
btnClick (btn) { btnClick (btn) {
debugger console.log(JSON.stringify(this.data, '', 2))
if (btn.btnType === 'BottomTab') {
if (btn.btnCode === 'save') {
alert('底部固定按钮的保存')
}
if (btn.btnCode === 'submit') {
alert('底部固定按钮的提交')
}
} if (btn.btnType === 'Button') {
if (btn.btnCode === 'nextBtn') {
alert('按钮继续')
}
}
}, },
}, },
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment