Commit 93176873 authored by 胡小根's avatar 胡小根

Merge branch 'master' of 115.28.80.125:softwarefactory/vueelementtemplate

parents e2b76f93 50c0f9d4
...@@ -109,6 +109,15 @@ export const asyncRouterMap = [ ...@@ -109,6 +109,15 @@ export const asyncRouterMap = [
title: '详情', title: '详情',
icon: 'table' icon: 'table'
} }
},
{
path: 'panel',
component: _import('haomo/components/panel/index'),
name: 'haomo-panel',
meta: {
title: '面板',
icon: 'table'
}
} }
] ]
}, },
......
<template> <template>
<el-row type="flex"> <el-row type="flex">
<el-col :span="6"><div></div></el-col> <el-col :span="24" class="detail-content">
<el-col :span="12" class="detail-content">
<h2 class="title">详情页面</h2> <h2 class="title">详情页面</h2>
<el-form :model="detail" ref="detail" label-width="110px" status-icon style="width:80%;margin:0 auto"> <el-form :data="detail" label-width="110px" status-icon style="width:80%;margin:0 auto">
<el-form-item label="姓名" prop="name"> <el-form-item v-for="(column,index) in showColumns" :key="index" :label="column.name">
<a href="#">{{detail.name}}</a> <div>{{detail[column.codeCamel]}}</div>
</el-form-item>
<el-form-item label="性别" prop="gender">
<div>{{detail.gender}}</div>
</el-form-item>
<el-form-item label="年龄" prop="age">
<div>{{detail.age}}</div>
</el-form-item>
<el-form-item label="出生日期" prop="date">
<div>{{detail.date}}</div>
</el-form-item>
<el-form-item label="照片" prop="img">
<img style="width: 50px;" :src=detail.img alt="...">
</el-form-item>
<el-form-item label="学历" prop="education">
<div>{{detail.education}}</div>
</el-form-item>
<el-form-item label="最常用的网站" prop="website">
<a :href="detail.website">{{detail.website}}</a>
</el-form-item>
<el-form-item label="最喜欢的颜色" prop="color" class="color">
<input type="color" v-model="detail.color" style="width:200px;height:36px;border:none;outline:0"/>
</el-form-item>
<el-form-item label="手机号" prop="phone">
<div>{{detail.phone}}</div>
</el-form-item>
<el-form-item label="邮箱" prop="email">
<div>{{detail.email}}</div>
</el-form-item>
<el-form-item label="住址" prop="address">
<div>{{detail.address}}</div>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-col> </el-col>
<el-col :span="6"><div ></div></el-col>
</el-row> </el-row>
</template> </template>
<script> <script>
import _ from 'lodash'
import request from '@/utils/request'
export default { export default {
name: 'HmComplexDetail', name: 'HmComplexDetail',
// 继承其他组件 // 继承其他组件
extends: {}, extends: {},
// 使用其它组件 // 使用其它组件
components: {}, components: {},
props: {
/**
* 组件所使用的表定义schema。表定义schema,请使用 model2codejs 从pdm文件生成schema。
* 对于所有毫末科技的组件,必须传schema,以完成数据的交互
*/
schema: {
type: Object,
required: true
},
/**
* 指定要显示的列。默认为根据schema得到的所有列。完整示例为:
* [
* {
* "name": "姓名",
* "code": "username",
* "render": function(value){
* return "<a href='value'></a>"
* }
* },
* "mobile",
* "sexual"
* ]
*/
columns: {
type: Array,
required: false,
validator: function(value) {
if (typeof value !== 'object') {
console.warn(`传入的columns不符合要求,必须是数组`)
return false
}
return true
}
},
/*
* 在详情页需要传入用户的id用来带出用户信息
* */
userId: {
type: null,
required: true
}
},
data() { data() {
return { return {
detail: { list: null,
name: 'haomokeji', detail: null,
gender: '男', showColumns: [] // 要显示的列数据
age: '18',
password: '123456',
website: 'https://www.baidu.com',
img: 'https://gss0.bdstatic.com/94o3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike272%2C5%2C5%2C272%2C90/sign=936c94db60600c33e474d69a7b253a6a/5243fbf2b21193134871a87f6e380cd790238dcb.jpg',
date: '2018/02/06',
education: '本科',
color: '#ff0000',
phone: '18034935566',
email: '18034935566@gmail.com',
address: '北京市海淀区文思海辉大厦'
}
} }
}, },
computed: { computed: {
...@@ -73,15 +76,79 @@ ...@@ -73,15 +76,79 @@
filters: { filters: {
}, },
created() { created() {
this.getList()
this.init()
}, },
methods: {} methods: {
validate() {
const self = this
// this.columns数组元素本身必须是string或者object. 且必须是schema中定义的列
// 由于vue中不允许通过其他的props来验证当前props,只能在created里进行调用
_.each(self.columns, function(item) {
if (!item) {
return 0
}
if (typeof item !== 'string' && typeof item !== 'object') {
console.error(`传入的columns不符合要求,数组元素必须是字符串或对象`)
}
if (typeof item === 'string' && !_.keyBy(self.schema['columns'], 'code')[item.toUpperCase()]) {
console.error(`传入的columns不符合要求,字符串元素[${item}]必须是schema中定义的列[code]`)
}
if (typeof item === 'object' && !_.keyBy(self.schema['columns'], 'code')[item['code'].toUpperCase()]) {
console.error(`传入的columns不符合要求,元素的code属性[${item['code']}]必须是schema中定义的列[code]`)
}
})
},
init() {
const self = this
// 处理要显示的列
if (!self.columns || !self.columns.length) {
_.each(self.schema['columns'], function(column) {
const tmp = JSON.parse(JSON.stringify(column))
self.showColumns.push(tmp)
})
} else {
self.showColumns = [];
// 将字符串对象进行替换处理
_.each(self.columns,function(item){
_.each(self.schema['columns'], function(column) {
if(item===column.codeCamel){
console.log(item);
const tmp = JSON.parse(JSON.stringify(column))
self.showColumns.push(tmp)
}
})
})
}
if (!request.defaults.baseURL) {
request.defaults.baseURL = '/org/api'
}
console.log(request.defaults)
console.log(`request.defaults.baseURL: ${request.defaults.baseURL}`)
},
getList: function() {
const self = this
self.listLoading = true
const params = {}
// 拿到所有的用户
request(self.schema.modelUnderscorePlural, {
params: params
}).then(resp => {
self.list = resp.data
// 匹配需要展示的用户
_.each(self.list, function(item) {
if (item.id === self.userId) {
self.detail = item
}
})
})
}
}
} }
</script> </script>
<style scoped> <style scoped>
.title{ .title{
text-align: center; text-align: center;
} }
.detail-content{
background-color: #F8F8F8;
}
</style> </style>
<template> <template>
<div> <div>
<hm-complex-detail> <!--<hm-complex-detail :schema="schema['HmUser']" :userId="userId">-->
<!--</hm-complex-detail>-->
<hm-complex-detail :schema="schema['HmUser']" :userId="userId" :columns="showUserColumns">
</hm-complex-detail> </hm-complex-detail>
</div> </div>
</template> </template>
<script> <script>
import HmComplexDetail from './HmComplexDetail.vue' import HmComplexDetail from './HmComplexDetail.vue'
import schema from '../../schemas/hm_org_schema'
export default { export default {
name: 'HmComplexDetail', name: 'HmComplexDetail',
...@@ -17,13 +20,17 @@ ...@@ -17,13 +20,17 @@
'hm-complex-detail': HmComplexDetail 'hm-complex-detail': HmComplexDetail
}, },
data() { data() {
return {} return {
showUserColumns: ['mobile', 'loginid']
}
}, },
computed: { computed: {
}, },
filters: { filters: {
}, },
created() { created() {
this.schema = schema
this.userId = '0e26566e953449a7a7500c34be39fd26'
}, },
methods: {} methods: {}
} }
......
输入姓名:
```jsx
<input/> JACK
```
选择性别:
```jsx
<input type="radio" value="男" name="gender"/>
<input type="radio" value="女" name="gender"/>
```
输入年龄:
```jsx
<input/> 18
```
输入出生日期:
```jsx
<input/> 20180207
```
上传照片:
```jsx
<input type="file"/>
```
学历:
```jsx
<select>
<option>博士</option>
<option>硕士</option>
<option>本科</option>
<option>专科</option>
<option>其他</option>
</select>
```
密码:
```jsx
<input type="password"/>
```
填写网站:
```jsx
<input type="url"/>
```
最喜欢的颜色:
```jsx
<input type="color"/>
```
填写手机号:
```jsx
<input type="number"/>
```
填写邮箱:
```jsx
<input type="email"/>
```
填写地址:
```jsx
<textarea>家庭地址</textarea>
```
```vue
<template>
<el-row type="flex" class="hm-form">
<!--左侧留白-->
<el-col :span="6"><div></div></el-col>
<el-col :span="12" style="border:1px solid orange"><div>
<!--标题-->
<h2 class="title">表单页面</h2>
<!--表单部分-->
<el-form :model="form" ref="form" :rules="rules" label-width="110px" status-icon style="width:80%;margin:0 auto">
<el-form-item label="姓名" prop="name">
<el-input type="text" v-model="form.name" autofocus placeholder="请输入姓名"></el-input>
</el-form-item>
<el-form-item label="性别" prop="gender">
<el-radio-group v-model="form.gender">
<el-radio label="男"></el-radio>
<el-radio label="女"></el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="年龄" prop="age">
<el-input type="age" v-model.number="form.age" placeholder="请输入年龄"></el-input>
</el-form-item>
<el-form-item label="出生日期" prop="date">
<el-date-picker v-model="form.date" type="date" placeholder="选择日期"></el-date-picker>
</el-form-item>
<el-form-item label="照片" prop="img">
<input type="file">
</el-form-item>
<!--选择学历-->
<el-form-item label="学历" prop="education">
<el-select v-model="form.education" placeholder="请选择学历">
<el-option label="博士" value="doctor"></el-option>
<el-option label="硕士" value="master"></el-option>
<el-option label="本科" value="bachelor"></el-option>
<el-option label="专科" value="professional"></el-option>
<el-option label="其他" value="others"></el-option>
</el-select>
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input type="password" v-model="form.password" placeholder="请输入密码"></el-input>
</el-form-item>
<el-form-item label="最常用的网站" prop="website">
<el-input type="url" v-model="form.url" placeholder="请输入网址"></el-input>
</el-form-item>
<el-form-item label="最喜欢的颜色" prop="color" class="color">
<input type="color" v-model="form.color" style="width:200px;height:36px;border:none;outline:0"/>
</el-form-item>
<el-form-item label="手机号" prop="phone">
<el-input v-model.number="form.phone" placeholder="请输入手机号"></el-input>
</el-form-item>
<el-form-item label="邮箱" prop="email">
<el-input v-model="form.email" placeholder="请输入邮箱"></el-input>
</el-form-item>
<el-form-item label="住址" prop="address">
<el-input type="textarea" placeholder="请填写地址" :autosize="{ minRows: 2, maxRows: 4}" resize="none" v-model="form.address"></el-input>
</el-form-item>
<!--确定提交和重置-->
<el-form-item>
<el-col :span="12">
<el-button type="primary" @click="onSubmit()">确定</el-button>
</el-col>
<el-col :span="12">
<el-button @click="resetForm()">重置</el-button>
</el-col>
</el-form-item>
</el-form>
</div>
</el-col>
<!--右侧留白-->
<el-col :span="6"><div></div></el-col>
</el-row>
</template>
<script>
/**
* 表单页面。
*/
export default {
name: 'HmComplexForm',
// 集成其他组件
extends: {},
// 使用其它组件
components: {},
// 混入公共对象
mixins: [],
props: {},
data() {
return {
form: {
name: '',
gender: '男',
age: '',
password: '',
website: '',
img: '',
date: '',
education: '',
color: '#ff0000',
phone: '',
email: '',
address: ''
},
rules: {
name: [
{ required: true, message: '请输入姓名', trigger: 'blur' },
{ min: 2, max: 5, message: '长度在 2 到 5 个字符', trigger: 'blur' }
],
age: [
{ required: true, message: '请输入年龄', trigger: 'blur' },
{ type: 'number', message: '年龄必须为数字', trigger: 'change' }
],
website: [
{ required: true, message: '请输入网址', trigger: 'blur' },
{ pattern: /[a-zA-z]+:\/\/[^\s]*/, message: '请输入正确的网址', trigger: 'change' }
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{ pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/, message: '密码必须同时包含数字和字母 6-20位', trigger: 'change' }
],
phone: [
{ type: 'number', required: true, message: '请输入手机号', trigger: 'blur' },
{ pattern: /^1[34578]\d{9}$/, message: '请输入正确的手机号', trigger: 'change' }
],
email: [
{ required: true, message: '请输入邮箱地址', trigger: 'blur' },
{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur,change' }
]
}
}
},
methods: {
// 提交
/**
* 确定提交函数。
*
* 所有选项输入正并验证通过,正确提交
* 验证失败,禁止提交并给出提示
*/
onSubmit() {
this.$refs.form.validate((valid) => {
if (valid) {
console.log('提交成功!')
} else {
console.log('提交失败!!')
return false
}
})
},
// 重置
/**
* 表单重置函数。
*
* 清空所有输入及提示信息。
*/
resetForm() {
this.$refs.form.resetFields()
}
}
}
</script>
<style scoped>
.title{
line-height: 40px;
background:orange;
color:#fff;
text-align:center;
margin-top:0;
}
</style>
```
<template> <template>
<div> <div>
<hm-complex-form> <hm-complex-form :schema="schema['HmUser']" :fields="showFields">
</hm-complex-form> </hm-complex-form>
</div> </div>
</template> </template>
<script> <script>
import HmComplexForm from './HmComplexForm.vue' import HmComplexForm from './HmComplexForm.vue'
import schema from '../../schemas/hm_org_schema'
export default { export default {
name: 'HmComplexForm', name: 'HmComplexForm',
...@@ -17,13 +18,16 @@ ...@@ -17,13 +18,16 @@
'hm-complex-form': HmComplexForm 'hm-complex-form': HmComplexForm
}, },
data() { data() {
return {} return {
showFields: ['username', 'loginid', 'password', 'mobile', 'email']
}
}, },
computed: { computed: {
}, },
filters: { filters: {
}, },
created() { created() {
this.schema = schema
}, },
methods: {} methods: {}
} }
......
<template>
<el-row type="flex">
<el-col :span="hmCollapse" class="detail-content" style="margin:0 auto">
<h2 class="title">面板页面</h2>
<el-card class="box-card" :style="hmStyle">
<div slot="header" class="clearfix" :class="hmTitleClass">
<span>{{hmTitle}}</span>
</div>
<div :style="hmPanelHeight" :class="hmContentClass">
<span>{{hmContentText}}</span>
<!--<el-form :data="detail" label-width="110px" status-icon style="width:80%;margin:0 auto">-->
<!--<el-form-item v-for="(column,index) in showColumns" :key="index" :label="column.name">-->
<!--<div>{{detail[column.codeCamel]}}</div>-->
<!--</el-form-item>-->
<!--</el-form>-->
</div>
</el-card>
</el-col>
</el-row>
</template>
<script>
import _ from 'lodash'
import request from '@/utils/request'
export default {
name: 'HmComplexDetail',
// 继承其他组件
extends: {},
// 使用其它组件
components: {},
props: {
/**
* 组件所使用的表定义schema。表定义schema,请使用 model2codejs 从pdm文件生成schema。
* 对于所有毫末科技的组件,必须传schema,以完成数据的交互
*/
schema: {
type: Object,
required: true
},
/**
* 指定要显示的列。默认为根据schema得到的所有列。完整示例为:
* [
* {
* "name": "姓名",
* "code": "username",
* "render": function(value){
* return "<a href='value'></a>"
* }
* },
* "mobile",
* "sexual"
* ]
*/
columns: {
type: Array,
required: false,
validator: function(value) {
if (typeof value !== 'object') {
console.warn(`传入的columns不符合要求,必须是数组`)
return false
}
return true
}
},
/*
* 在详情页需要传入用户的id用来带出用户信息
* */
userId: {
type: null,
required: true
},
hmTitle: {
type: null,
required: false
},
hmTitleClass: {
type: null,
required: false
},
hmContentClass: {
type: null,
required: false
},
hmContentText: {
type: null,
required: false
},
hmStyle: {
type: Object,
required: false
},
hmPanelHeight: {
type: Object,
required: false
},
hmCollapse: {
type: null,
required: false
}
},
data() {
return {
list: null,
detail: null,
showColumns: [] // 要显示的列数据
}
},
computed: {
},
filters: {
},
created() {
this.getList()
this.init()
},
methods: {
validate() {
const self = this
// this.columns数组元素本身必须是string或者object. 且必须是schema中定义的列
// 由于vue中不允许通过其他的props来验证当前props,只能在created里进行调用
_.each(self.columns, function(item) {
if (!item) {
return 0
}
if (typeof item !== 'string' && typeof item !== 'object') {
console.error(`传入的columns不符合要求,数组元素必须是字符串或对象`)
}
if (typeof item === 'string' && !_.keyBy(self.schema['columns'], 'code')[item.toUpperCase()]) {
console.error(`传入的columns不符合要求,字符串元素[${item}]必须是schema中定义的列[code]`)
}
if (typeof item === 'object' && !_.keyBy(self.schema['columns'], 'code')[item['code'].toUpperCase()]) {
console.error(`传入的columns不符合要求,元素的code属性[${item['code']}]必须是schema中定义的列[code]`)
}
})
},
init() {
const self = this
// 处理要显示的列
if (!self.columns || !self.columns.length) {
_.each(self.schema['columns'], function(column) {
const tmp = JSON.parse(JSON.stringify(column))
self.showColumns.push(tmp)
})
} else {
self.showColumns = [];
// 将字符串对象进行替换处理
_.each(self.schema['columns'], function(column) {
_.each(self.columns,function(item){
if(column.codeCamel===item){
const tmp = JSON.parse(JSON.stringify(column))
self.showColumns.push(tmp)
}
})
})
}
if (!request.defaults.baseURL) {
request.defaults.baseURL = '/org/api'
}
console.log(request.defaults)
console.log(`request.defaults.baseURL: ${request.defaults.baseURL}`)
},
getList: function() {
const self = this
self.listLoading = true
const params = {}
// 拿到所有的用户
request(self.schema.modelUnderscorePlural, {
params: params
}).then(resp => {
self.list = resp.data
// 匹配需要展示的用户
_.each(self.list, function(item) {
if (item.id === self.userId) {
self.detail = item
}
})
})
}
}
}
</script>
<style scoped>
.title{
text-align: center;
}
.center{
text-align: center;
}
</style>
<template>
<div>
<hm-complex-panel :schema="schema['HmUser']" :userId="userId" :hmTitle="hmTitle" :hmTitleClass="hmTitleClass"
:hmContentText="hmContentText" :hmStyle="hmStyle" :hmPanelHeight="hmPanelHeight" :hmCollapse="collapses">
</hm-complex-panel>
<hm-complex-panel :schema="schema['HmUser']" :userId="userId" :hmTitle="titleBak" :hmContentClass="hmContentClass" :showFields="showFields"
:hmContentText="hmContentTextBak" :hmStyle="styleBak" :hmPanelHeight="panelHeightBak" :hmCollapse="collapseBak">
</hm-complex-panel>
</div>
</template>
<script>
import HmComplexPanel from './HmComplexPanel.vue'
import schema from '../../schemas/hm_org_schema'
export default {
name: 'HmComplexPanel',
// 继承其他组件
extends: {},
// 使用其它组件
components: {
'hm-complex-panel': HmComplexPanel
},
data() {
return {
showFields: ['username', 'loginid', 'password', 'mobile', 'email']
}
},
computed: {
},
filters: {
},
created() {
this.schema = schema
this.userId = '0e26566e953449a7a7500c34be39fd26'
this.hmTitle = '面版名称'
this.hmTitleClass = 'center'
this.hmContentClass = 'center'
this.hmContentText = '面板文字'
this.hmStyle = {
width: '50%',
background: '#42b983',
margin: '0 auto'
}
this.hmPanelHeight = {
height: '100px'
}
this.collapses = 12
this.showFields = ['username', 'loginid', 'password', 'mobile', 'email']
this.titleBak = '测试面板'
this.hmContentTextBak = '我测试一下'
this.styleBak = {
width: '100%',
background: '#f56c6c',
marginBottom: '20px'
}
this.panelHeightBak = {
height: '200px'
}
this.collapseBak = 22
},
methods: {}
}
</script>
<style scoped>
</style>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<!-- 表格 --> <!-- 表格 -->
<el-table :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row <el-table :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row
style="width: 100%"> style="width: 100%">
<el-table-column v-for="column in showColumns" align="center" :label="column.name"> <el-table-column v-for="(column,index) in showColumns" :key="index" align="center" :label="column.name">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ scope.row[column.code] }}</span> <span>{{ scope.row[column.code] }}</span>
</template> </template>
...@@ -241,16 +241,22 @@ ...@@ -241,16 +241,22 @@
self.$set(tmp, 'code', tmp.code.toLowerCase()) self.$set(tmp, 'code', tmp.code.toLowerCase())
self.showColumns.push(tmp) self.showColumns.push(tmp)
}) })
console.log(self.showColumns)
} else { } else {
self.showColumns = JSON.parse(JSON.stringify(self.columns)) self.showColumns = JSON.parse(JSON.stringify(self.columns))
console.log('1111111')
console.log(self.showColumns)
// 将字符串对象进行替换处理 // 将字符串对象进行替换处理
_.each(self.showColumns, function(column, index) { _.each(self.showColumns, function(column, index) {
if (typeof column === 'string') { if (typeof column === 'string') {
const tmp = _.keyBy(self.schema['columns'], 'code')[column.toUpperCase()] const tmp = _.keyBy(self.schema['columns'], 'code')[column.toUpperCase()]
console.log(tmp)
self.$set(tmp, 'code', tmp.code.toLowerCase()) self.$set(tmp, 'code', tmp.code.toLowerCase())
self.$set(self.showColumns, index, tmp) self.$set(self.showColumns, index, tmp)
} }
}) })
console.log('2222222')
console.log(self.showColumns)
} }
// 处理过滤条件 // 处理过滤条件
......
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