Commit 67e95b6d authored by 胡小根's avatar 胡小根

Merge branch 'master' of 115.28.80.125:softwarefactory/vueelementtemplate

parents 6d7adb9a 4e5d9dd9
......@@ -39,6 +39,7 @@
"vue-count-to": "1.0.13",
"vue-i18n": "7.3.2",
"vue-multiselect": "2.0.8",
"vue-quill-editor": "^3.0.5",
"vue-router": "3.0.1",
"vue-splitpane": "1.0.2",
"vuedraggable": "2.15.0",
......@@ -46,7 +47,9 @@
"xlsx": "^0.11.16"
},
"pre-commit": {
"run": ["lint"]
"run": [
"lint"
]
},
"devDependencies": {
"autoprefixer": "7.2.3",
......
import Vue from 'vue'
import VueQuillEditor from 'vue-quill-editor' // 富文本插件
import 'normalize.css/normalize.css'// A modern alternative to CSS resets
......@@ -17,12 +18,16 @@ import './errorLog'// error log
import './permission' // permission control
import './mock' // simulation data
import 'quill/dist/quill.core.css' // 富文本CSS
import 'quill/dist/quill.snow.css' // 富文本CSS
import * as filters from './filters' // global filters
import Icon from 'vue-awesome/components/Icon'
Vue.component('icon', Icon)
Vue.use(VueQuillEditor) // 富文本
Vue.use(Element, {
size: 'medium', // set element-ui default size
i18n: (key, value) => i18n.t(key, value)
......
......@@ -123,6 +123,7 @@ export const asyncRouterMap = [
},
{
path: '/haomo/pages',
component: _import('haomo/pages/index'),
redirect: '/haomo/pages/login',
name: 'haomo-pages',
meta: {
......@@ -132,7 +133,7 @@ export const asyncRouterMap = [
children: [
{
path: 'login',
component: _import('haomo/pages/login'),
component: _import('haomo/pages/login/index'),
name: 'haomo-login',
meta: {
title: '登录',
......@@ -141,7 +142,7 @@ export const asyncRouterMap = [
},
{
path: 'personal',
component: _import('haomo/pages/personal'),
component: _import('haomo/pages/personal-center/index'),
name: 'haomo-personal',
meta: {
title: '个人中心',
......
### 基本使用
```jsx
<hm-complex-detail :userId="0e26566e953449a7a7500c34be39fd26"
<hm-complex-detail :tableId="0e26566e953449a7a7500c34be39fd26"
:schema="{
'model': 'HmUser',
'modelPlural': 'HmUsers',
'modelCamel': 'hmUser',
'modelCamelPlural': 'hmUsers',
'modelUnderscore': 'hm_user',
'modelUnderscorePlural': 'hm_users',
'columns': [
{
'id': 'o50',
'objectId': '170A4473-36CC-47E1-96C3-F238F8132AA4',
'name': '用户名字',
'code': 'USERNAME',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1517859502',
'modifier': 'hm20160509',
'dataType': 'VARCHAR2(256CHAR)',
'length': '256',
'codeCamel': 'username',
'codeCamelPlural': 'usernames',
'codeUnderscore': 'username',
'codeUnderscorePlural': 'usernames',
'type': 'string'
},
{
'id': 'o51',
'objectId': '70EC38C6-4AE4-4E79-BA72-29DA2FE50782',
'name': '登录ID',
'code': 'LOGINID',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'VARCHAR2(256CHAR)',
'length': '256',
'columnMandatory': '1',
'codeCamel': 'loginid',
'codeCamelPlural': 'loginids',
'codeUnderscore': 'loginid',
'codeUnderscorePlural': 'loginids',
'type': 'string'
},
{
'id': 'o52',
'objectId': '4FCE7185-D489-4DED-AA5F-093A4DBC1112',
'name': '密码',
'code': 'PASSWORD',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'VARCHAR2(256CHAR)',
'length': '256',
'codeCamel': 'password',
'codeCamelPlural': 'passwords',
'codeUnderscore': 'password',
'codeUnderscorePlural': 'passwords',
'type': 'string'
},
{
'id': 'o53',
'objectId': '3A897125-CB02-40F5-9BB1-62A9B06553E0',
'name': '联系电话',
'code': 'MOBILE',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'VARCHAR2(16CHAR)',
'length': '16',
'codeCamel': 'mobile',
'codeCamelPlural': 'mobiles',
'codeUnderscore': 'mobile',
'codeUnderscorePlural': 'mobiles',
'type': 'string'
},
{
'id': 'o54',
'objectId': '48B9C079-3CCA-4886-9543-3AE764998E9A',
'name': '邮箱',
'code': 'EMAIL',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'VARCHAR2(256CHAR)',
'length': '256',
'codeCamel': 'email',
'codeCamelPlural': 'emails',
'codeUnderscore': 'email',
'codeUnderscorePlural': 'emails',
'type': 'string'
},
{
'id': 'o55',
'objectId': '533AB6E8-A3D0-473D-9DE6-0D0CABA6731C',
'name': '头像',
'code': 'AVATAR',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'VARCHAR2(1024CHAR)',
'length': '1024',
'codeCamel': 'avatar',
'codeCamelPlural': 'avatars',
'codeUnderscore': 'avatar',
'codeUnderscorePlural': 'avatars',
'type': 'string'
},
{
'id': 'o56',
'objectId': 'EF44AF1F-F6B9-412F-9FF7-AAECD6B5521A',
'name': '创建时间',
'code': 'CREATE_TIME',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'DATE',
'codeCamel': 'createTime',
'codeCamelPlural': 'createTimes',
'codeUnderscore': 'create_time',
'codeUnderscorePlural': 'create_times',
'type': 'datetime'
},
{
'id': 'o57',
'objectId': 'CD1BC772-356B-4D14-A40E-28F115F95EEC',
'name': '更新时间',
'code': 'LAST_UPDATE_TIME',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'DATE',
'codeCamel': 'lastUpdateTime',
'codeCamelPlural': 'lastUpdateTimes',
'codeUnderscore': 'last_update_time',
'codeUnderscorePlural': 'last_update_times',
'type': 'datetime'
},
{
'id': 'o58',
'objectId': '297D03AE-459D-4991-A459-3449FE893EEB',
'name': '最后登录时间',
'code': 'LAST_LOGIN_TIME',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'DATE',
'codeCamel': 'lastLoginTime',
'codeCamelPlural': 'lastLoginTimes',
'codeUnderscore': 'last_login_time',
'codeUnderscorePlural': 'last_login_times',
'type': 'datetime'
},
{
'id': 'o59',
'objectId': '6767F0FE-6C49-46F3-919E-D854C21FCA52',
'name': '安全级别',
'code': 'SECURITY_LEVEL',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'NUMBER(11,0)',
'length': '11',
'codeCamel': 'securityLevel',
'codeCamelPlural': 'securityLevels',
'codeUnderscore': 'security_level',
'codeUnderscorePlural': 'security_levels',
'type': 'number'
},
{
'id': 'o60',
'objectId': 'C4BF570D-C8FC-4B72-919C-78DB3D790171',
'name': '类型',
'code': 'TYPE',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'comment': '1:企业,2:代理商',
'dataType': 'NUMBER(11,0)',
'length': '11',
'codeCamel': 'type',
'codeCamelPlural': 'types',
'codeUnderscore': 'type',
'codeUnderscorePlural': 'types',
'type': 'number'
}
]
}"></hm-complex-detail>
'model': 'HmUser',
'modelPlural': 'HmUsers',
'modelCamel': 'hmUser',
'modelCamelPlural': 'hmUsers',
'modelUnderscore': 'hm_user',
'modelUnderscorePlural': 'hm_users',
'columns': [
{
'id': 'o50',
'objectId': '170A4473-36CC-47E1-96C3-F238F8132AA4',
'name': '用户名字',
'code': 'USERNAME',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1517859502',
'modifier': 'hm20160509',
'dataType': 'VARCHAR2(256CHAR)',
'length': '256',
'codeCamel': 'username',
'codeCamelPlural': 'usernames',
'codeUnderscore': 'username',
'codeUnderscorePlural': 'usernames',
'type': 'string'
},
{
'id': 'o51',
'objectId': '70EC38C6-4AE4-4E79-BA72-29DA2FE50782',
'name': '登录ID',
'code': 'LOGINID',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'VARCHAR2(256CHAR)',
'length': '256',
'columnMandatory': '1',
'codeCamel': 'loginid',
'codeCamelPlural': 'loginids',
'codeUnderscore': 'loginid',
'codeUnderscorePlural': 'loginids',
'type': 'string'
},
{
'id': 'o52',
'objectId': '4FCE7185-D489-4DED-AA5F-093A4DBC1112',
'name': '密码',
'code': 'PASSWORD',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'VARCHAR2(256CHAR)',
'length': '256',
'codeCamel': 'password',
'codeCamelPlural': 'passwords',
'codeUnderscore': 'password',
'codeUnderscorePlural': 'passwords',
'type': 'string'
},
{
'id': 'o53',
'objectId': '3A897125-CB02-40F5-9BB1-62A9B06553E0',
'name': '联系电话',
'code': 'MOBILE',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'VARCHAR2(16CHAR)',
'length': '16',
'codeCamel': 'mobile',
'codeCamelPlural': 'mobiles',
'codeUnderscore': 'mobile',
'codeUnderscorePlural': 'mobiles',
'type': 'string'
},
{
'id': 'o54',
'objectId': '48B9C079-3CCA-4886-9543-3AE764998E9A',
'name': '邮箱',
'code': 'EMAIL',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'VARCHAR2(256CHAR)',
'length': '256',
'codeCamel': 'email',
'codeCamelPlural': 'emails',
'codeUnderscore': 'email',
'codeUnderscorePlural': 'emails',
'type': 'string'
},
{
'id': 'o55',
'objectId': '533AB6E8-A3D0-473D-9DE6-0D0CABA6731C',
'name': '头像',
'code': 'AVATAR',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'VARCHAR2(1024CHAR)',
'length': '1024',
'codeCamel': 'avatar',
'codeCamelPlural': 'avatars',
'codeUnderscore': 'avatar',
'codeUnderscorePlural': 'avatars',
'type': 'string'
},
{
'id': 'o56',
'objectId': 'EF44AF1F-F6B9-412F-9FF7-AAECD6B5521A',
'name': '创建时间',
'code': 'CREATE_TIME',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'DATE',
'codeCamel': 'createTime',
'codeCamelPlural': 'createTimes',
'codeUnderscore': 'create_time',
'codeUnderscorePlural': 'create_times',
'type': 'datetime'
},
{
'id': 'o57',
'objectId': 'CD1BC772-356B-4D14-A40E-28F115F95EEC',
'name': '更新时间',
'code': 'LAST_UPDATE_TIME',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'DATE',
'codeCamel': 'lastUpdateTime',
'codeCamelPlural': 'lastUpdateTimes',
'codeUnderscore': 'last_update_time',
'codeUnderscorePlural': 'last_update_times',
'type': 'datetime'
},
{
'id': 'o58',
'objectId': '297D03AE-459D-4991-A459-3449FE893EEB',
'name': '最后登录时间',
'code': 'LAST_LOGIN_TIME',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'DATE',
'codeCamel': 'lastLoginTime',
'codeCamelPlural': 'lastLoginTimes',
'codeUnderscore': 'last_login_time',
'codeUnderscorePlural': 'last_login_times',
'type': 'datetime'
},
{
'id': 'o59',
'objectId': '6767F0FE-6C49-46F3-919E-D854C21FCA52',
'name': '安全级别',
'code': 'SECURITY_LEVEL',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'dataType': 'NUMBER(11,0)',
'length': '11',
'codeCamel': 'securityLevel',
'codeCamelPlural': 'securityLevels',
'codeUnderscore': 'security_level',
'codeUnderscorePlural': 'security_levels',
'type': 'number'
},
{
'id': 'o60',
'objectId': 'C4BF570D-C8FC-4B72-919C-78DB3D790171',
'name': '类型',
'code': 'TYPE',
'creationDate': '1498990741',
'creator': 'hm20160509',
'modificationDate': '1498995491',
'modifier': 'xjq',
'comment': '1:企业,2:代理商',
'dataType': 'NUMBER(11,0)',
'length': '11',
'codeCamel': 'type',
'codeCamelPlural': 'types',
'codeUnderscore': 'type',
'codeUnderscorePlural': 'types',
'type': 'number'
}
]
}"></hm-complex-detail>
```
### 指定列表显示的列
......@@ -205,23 +205,15 @@
<template>
<div>
<hm-complex-detail :schema="schema['HmUser']"
:userId="userId"
:tableId="tableId"
:columns="showUserColumns">
</hm-complex-detail>
</div>
</template>
<script>
import HmComplexDetail from './HmComplexDetail.vue'
import schema from '../../schemas/hm_org_schema'
<script>
export default {
name: 'HmComplexDetail',
// 继承其他组件
extends: {},
// 使用其它组件
components: {
'hm-complex-detail': HmComplexDetail
},
data() {
return {
schema: {
......@@ -430,7 +422,8 @@
filters: {
},
created() {
this.userId = '0e26566e953449a7a7500c34be39fd26'
this.tableId = '0e26566e953449a7a7500c34be39fd26'
this.schema = schema
},
methods: {}
}
......
<template>
<el-row type="flex">
<el-col :span="24" class="detail-content">
<h2 class="title">详情页面</h2>
<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>
......@@ -56,11 +55,11 @@
return true
}
},
/*
* 在详情页需要传入用户的id用来带出用户信息
* */
userId: {
type: null,
/**
* 在详情页需要传入用户的id用来带出用户信息
*/
tableId: {
type: String,
required: true
}
},
......@@ -68,7 +67,7 @@
return {
list: null,
detail: null,
showColumns: [] // 要显示的列数据
showColumns: [] // 要显示的列数据,
}
},
computed: {
......@@ -138,7 +137,7 @@
self.list = resp.data
// 匹配需要展示的用户
_.each(self.list, function(item) {
if (item.id === self.userId) {
if (item.id === self.tableId) {
self.detail = item
}
})
......
<template>
<div>
<hm-complex-detail :schema="schema['HmUser']" :userId="userId">
<hm-complex-detail :schema="schema['HmUser']" :tableId="tableId">
</hm-complex-detail>
<hm-complex-detail :schema="schema['HmUser']" :userId="userId" :columns="showUserColumns">
<hm-complex-detail :schema="schema['HmUser']" :tableId="tableId" :columns="showUserColumns">
</hm-complex-detail>
</div>
</template>
......@@ -30,7 +30,7 @@
},
created() {
this.schema = schema
this.userId = '0e26566e953449a7a7500c34be39fd26'
this.tableId = '0e26566e953449a7a7500c34be39fd26'
},
methods: {}
}
......
### 基本使用
```jsx
<hm-complex-form :fields="['username', 'loginid', 'password', 'mobile', 'email']"
<hm-complex-form :tableId="tableId"
:columns="['username', 'loginid', 'password', 'mobile', 'email']"
:schema="{
'model': 'HmUser',
'modelPlural': 'HmUsers',
......@@ -204,8 +205,10 @@
```vue
<template>
<div>
<hm-complex-form :schema="schema['HmUser']"
:fields="showFields">
<hm-complex-form
:tableId="tableId"
:schema="schema['HmUser']"
:columns="showUserColumns">
</hm-complex-form>
</div>
</template>
......@@ -413,11 +416,12 @@
]
}
},
showFields: ['username', 'loginid', 'password', 'mobile', 'email']
showUserColumns: ['username', 'loginid', 'password', 'mobile', 'email']
}
},
created() {
this.schema = schema
this.tableId = '0e26566e953449a7a7500c34be39fd26'
}
}
</script>
......
......@@ -8,11 +8,19 @@
<!--表单部分-->
<el-form ref="form" :model="formModel" :rules="rules" label-width="110px"
style="width:80%;margin:0 auto">
<el-form-item v-for="(column,index) in showFields" :key="index" :label="column.name" :prop="column.codeCamel">
<el-input v-if="column.codeCamel==='password'" type="password" :placeholder="column.name"
v-model="formModel[column.codeCamel]"></el-input>
<el-input v-if="column.codeCamel!=='password'" :placeholder="column.name"
v-model="formModel[column.codeCamel]"></el-input>
<el-form-item v-for="(column,index) in showUserColumns" :key="index" :label="column.name" :prop="column.codeCamel">
<!--el-input<el-input v-if="column.codeCamel==='password'" type="password"
v-model="formModel[column.codeCamel]"></el-input>-->
<el-input v-if="column.codeCamel!=='securityLevel'" v-model="formModel[column.codeCamel]"></el-input>
<!-- quill-editor -->
<quill-editor v-if="column.codeCamel==='securityLevel'" class="editor-example bubble"
ref="textEditor"
v-model="formModel[column.codeCamel]"
:options="editorOption"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@ready="onEditorReady($event)">
</quill-editor>
</el-form-item>
<el-form-item>
<el-col :span="12">
......@@ -36,7 +44,10 @@
import request from '@/utils/request'
/**
* 表单页面。
* 毫末科技的表单组件.
*
* demo地址: factory.haomo-studio.com/vue-element/#/haomo/components/forms
* @author 王康
*/
export default {
name: 'HmComplexForm',
......@@ -58,24 +69,31 @@
/**
* 指定要显示的字段。默认为根据schema得到的所有字段。
*/
fields: {
columns: {
type: Array,
required: false,
validator: function(value) {
if (typeof value !== 'object') {
console.warn(`传入的fields不符合要求,必须是数组`)
console.warn(`传入的columns不符合要求,必须是数组`)
return false
}
return true
}
},
/**
* 传入用户的id用来修改用户信息
*/
tableId: {
type: String,
required: false
}
},
data() {
return {
form: null,
formModel: {}, // 双向绑定的数据变量
showFields: [], // 要显示的字段
showUserColumns: [], // 要显示的字段
// form: {
// name: '',
// gender: '男',
......@@ -99,8 +117,8 @@
{ required: true, message: '请输入登陆ID', trigger: 'blur' }
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{ pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/, message: '密码必须同时包含数字和字母 6-20位', trigger: 'change' }
{ required: true, message: '请输入密码', trigger: 'blur' }
// { pattern: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/, message: '密码必须同时包含数字和字母 6-20位', trigger: 'change' }
],
mobile: [
{ pattern: /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/, message: '请输入正确的电话号码或手机号', trigger: 'blur&change' }
......@@ -108,45 +126,84 @@
email: [
{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur&change' }
]
},
editorOption: {
placeholder: '',
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'],
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'color': [] }, { 'background': [] }],
['image']
]
}
}
}
},
created() {
// this.validate()
this.init()
// console.log(this.schema)
},
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]`)
}
})
},
onEditorBlur(editor) {
console.log('editor blur!')
},
onEditorFocus(editor) {
console.log('editor focus!')
},
onEditorReady(editor) {
console.log('editor ready!')
},
init() {
const self = this
// 如果没有传fields,则全部显示
if (!self.fields || !self.fields.length) {
// 如果没有传columns,则全部显示
if (!self.columns || !self.columns.length) {
_.each(self.schema['columns'], function(column) {
const tmp = JSON.parse(JSON.stringify(column))
// self.$set(tmp, 'code', tmp.code.toLowerCase())
self.showFields.push(tmp)
self.$set(tmp, 'code', tmp.code.toLowerCase())
self.showUserColumns.push(tmp)
})
// console.log(self.showFields)
} else { // 如果传入了fields,则只显示传入的字段
self.showFields = JSON.parse(JSON.stringify(self.fields))
// console.log(self.showUserColumns)
} else { // columns,则只显示传入的字段
self.showUserColumns = JSON.parse(JSON.stringify(self.columns))
// console.log('1111111')
// console.log(self.showFields)
console.log(self.showUserColumns)
// 将字符串对象进行替换处理
_.each(self.showFields, function(column, index) {
_.each(self.showUserColumns, function(column, index) {
if (typeof column === 'string') {
// 生成一个新对象
console.log(column)
const tmp = _.keyBy(self.schema['columns'], 'code')[column.toUpperCase()]
// console.log(tmp)
// self.$set(tmp, 'code', tmp.code.toLowerCase())
self.$set(self.showFields, index, tmp)
// const tmp = _.keyBy(self.schema['columns'], 'code')[column.toUpperCase()]
const tmp = _.keyBy(self.schema['columns'], 'codeCamel')[column]
self.$set(tmp, 'code', tmp.code.toLowerCase())
self.$set(self.showUserColumns, index, tmp)
}
})
// console.log('2222222')
console.log(self.showFields)
console.log(self.showUserColumns)
}
// 提取v-model绑定的变量
_.each(self.showFields, function(item) {
_.each(self.showUserColumns, function(item) {
self.formModel[item.codeCamel] = ''
})
console.log(self.formModel)
......@@ -168,22 +225,46 @@
self.$refs.form.validate((valid) => {
if (valid) {
console.log('提交成功!')
request(self.schema.modelUnderscorePlural + '/new', {
method: 'post',
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
data: self.formModel,
transformRequest:
function(obj) {
var str = []
for (var p in obj) {
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]))
// 存在tableId 则修改信息
if (self.tableId) {
request(self.schema.modelUnderscorePlural + '/' + self.tableId + '/edit', {
method: 'post',
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
data: self.formModel,
transformRequest:
function(obj) {
var str = []
// 删除空值的属性
obj = _.omitBy(obj, function(value) {
return !value
})
for (var p in obj) {
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]))
}
return str.join('&')
}
return str.join('&')
}
}).then(resp => {
console.log(resp.data)
self.resetForm()
})
}).then(resp => {
console.log('修改成功')
self.resetForm()
})
} else { // 不存在tableId 则创建一条数据
request(self.schema.modelUnderscorePlural + '/new', {
method: 'post',
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' },
data: self.formModel,
transformRequest:
function(obj) {
var str = []
for (var p in obj) {
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]))
}
return str.join('&')
}
}).then(resp => {
console.log('创建成功')
self.resetForm()
})
}
} else {
console.log('提交失败!!')
return false
......
<template>
<div>
<hm-complex-form :schema="schema['HmUser']" :fields="showFields">
<hm-complex-form :schema="schema['HmUser']" :columns="showUserColumns" :tableId="tableId">
</hm-complex-form>
</div>
</template>
......@@ -19,7 +19,8 @@
},
data() {
return {
showFields: ['username', 'loginid', 'password', 'mobile', 'email']
showUserColumns: ['username', 'loginid', 'password', 'mobile', 'email', 'securityLevel']
// showUserColumns: []
}
},
computed: {
......@@ -28,6 +29,7 @@
},
created() {
this.schema = schema
this.tableId = '0e26566e953449a7a7500c34be39fd26'
},
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>
### 基本使用
```jsx
<hm-panel :options="{
'panel_class': 'center',
'title_class': 'weight',
'content_class': 'center',
'panel_style': {
width: '100%',
margin: '20px auto'
},
'panel_span': 22,
'content_height': {
height: '600px'
},
'canCollapse': true
}">
<div slot="title">面板标题</div>
<div slot="content">面板内容</div>
</hm-panel>
```
### 不可收起的panel
```vue
<template>
<div>
<hm-panel :options="options">
<div slot="title">测试面板</div>
<div slot="content">面板内容</div>
</hm-panel>
</div>
</template>
<script>
export default {
name: 'HmPanel',
data() {
return {
}
},
created() {
this.options = {
panel_class: 'center',
title_class: 'center',
content_class: 'center',
panel_style: {
width: '80%',
background: '#42b983',
margin: '0 auto'
},
panel_span: 20,
canCollapse: false
}
this.schema = schema
this.showFields = ['username', 'loginid', 'password', 'mobile', 'email']
}
}
</script>
```
\ No newline at end of file
<template>
<el-row type="flex">
<el-col :span="options.panel_span" class="detail-content" :class="options.panel_class" style="margin:0 auto">
<el-card class="box-card" :style="options.panel_style">
<div slot="header" class="clearfix" :class="[options.title_class, options.canCollapse ? 'pointer' : '']" @click="toggle()">
<slot name="title"></slot>
</div>
<div :style="options.content_height" :class="options.content_class" v-show="collapse">
<slot name="content"></slot>
</div>
</el-card>
</el-col>
</el-row>
</template>
<script>
export default {
name: 'HmPanel',
// 继承其他组件
extends: {},
// 使用其它组件
components: {},
props: {
/**
* 在面板页传入面板对象
* 完整示例为:{ panel_class: '面板类名', title_class: '标题类名', content_class: '内容类名', panel_style: '面板样式',
* panel_span: '面板宽度比例', content_height: '内容高度', canCollapse: '是否可收起'}
*/
options: {
type: Object,
required: true
}
},
data() {
return {
collapse: true
}
},
computed: {
},
filters: {
},
created() {
},
methods: {
toggle() {
if (this.options.canCollapse) {
this.collapse = !this.collapse
console.log('收起展开')
} else {
console.log('不可收起')
}
}
}
}
</script>
<style scoped>
.weight{
font-weight: 700;
}
.center{
text-align: center;
}
.pointer{
cursor:pointer;
}
</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>
<hm-panel :options="options">
<div slot="title">面板标题</div>
<div slot="content">
<hm-complex-detail :schema="schema['HmUser']" :tableId="userId">
</hm-complex-detail>
</div>
</hm-panel>
<hm-panel :options="options2">
<div slot="title">
<hm-complex-form :schema="schema['HmUser']" :fields="showFields"></hm-complex-form>
</div>
<div slot="content">
<hm-complex-form :schema="schema['HmUser']" :fields="showFields"></hm-complex-form>
</div>
</hm-panel>
</div>
</template>
<script>
import HmComplexPanel from './HmComplexPanel.vue'
import HmPanel from './HmPanel.vue'
import schema from '../../schemas/hm_org_schema'
import HmComplexDetail from '../details/HmComplexDetail.vue'
import HmComplexForm from '../forms/HmComplexForm.vue'
export default {
name: 'HmComplexPanel',
name: 'HmPanel',
// 继承其他组件
extends: {},
// 使用其它组件
components: {
'hm-complex-panel': HmComplexPanel
'hm-panel': HmPanel,
'hm-complex-detail': HmComplexDetail,
'hm-complex-form': HmComplexForm
},
data() {
return {
......@@ -31,33 +44,35 @@
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.options = {
panel_class: 'center',
title_class: 'weight',
content_class: 'center',
panel_style: {
width: '100%',
margin: '20px auto'
},
panel_span: 22,
content_height: {
height: '600px'
},
canCollapse: true
}
this.hmPanelHeight = {
height: '100px'
this.options2 = {
panel_class: 'center',
title_class: 'center',
content_class: 'center',
panel_style: {
width: '80%',
background: '#42b983',
margin: '0 auto'
},
panel_span: 20,
canCollapse: false
}
this.collapses = 12
this.schema = schema
this.userId = '0e26566e953449a7a7500c34be39fd26'
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: {}
}
......
......@@ -242,7 +242,9 @@
// 将字符串对象进行替换处理
_.each(self.showColumns, function(column, index) {
if (typeof column === 'string') {
const tmp = _.keyBy(self.schema['columns'], 'code')[column.toUpperCase()]
// const tmp = _.keyBy(self.schema['columns'], 'code')[column.toUpperCase()]
// 王康 修改 2018年02月25日22:58:23
const tmp = _.keyBy(self.schema['columns'], 'codeCamel')[column]
console.log(tmp)
self.$set(tmp, 'code', tmp.code.toLowerCase())
self.$set(self.showColumns, index, tmp)
......
<template>
<transition name="fade" mode="out-in">
<keep-alive :include='cachedViews'>
<router-view></router-view>
</keep-alive>
</transition>
</template>
<script>
export default {
name: 'PagesMain',
computed: {
cachedViews() {
return this.$store.state.tagsView.cachedViews
}
}
}
</script>
<template>
<el-row type="flex">
<el-col :span="10" class="detail-content" style="margin:0 auto" >
<el-form style="border: 0.5px solid #e6ebf5">
<el-row type="flex">
<el-col style="height: 45px;background-color: #00BF8B" ></el-col>
</el-row>
<el-row type="flex" style="margin-top:35px">
<el-col style="margin: 0 auto;height: 70px;width:433px;text-align: center;line-height: 70px;font-size: 35px;color:#586C8C;font-weight: bold" >
<img />张家口人民检察院
</el-col>
</el-row>
<el-form-item prop="pass">
<el-input class="style" style="width:433px;margin: 0 auto;margin-top:25px;display: block;" prefix-icon="el-icon-search" auto-complete="off"></el-input>
</el-form-item>
<el-form-item prop="checkPass">
<el-input type="password" style="width:433px;margin: 0 auto;display: block;border-width: 0px;border-bottom-width: 1px;border-radius: 0px;" prefix-icon="el-icon-search" suffix-icon="el-icon-view" auto-complete="off"></el-input>
</el-form-item>
<el-form-item>
<el-button type="success" style="width: 178px;height: 44px ;font-size:16px;background-color: #00BF8B;margin: 0 auto;display: block">提交</el-button>
</el-form-item>
</el-form>
</el-col>
</el-row>
</template>
<script>
export default {
name: 'HmLogin',
// 继承其他组件
extends: {},
// 使用其它组件
components: {},
props: {
options: {
type: Object,
required: false
}
},
data() {
},
computed: {
},
filters: {
},
created() {
},
methods: {
}
}
</script>
<style scoped>
</style>
<template>
<div>
<hm-login></hm-login>
</div>
</template>
<script>
import HmLogin from './HmLogin.vue'
export default {
name: 'login',
// 继承其他组件
extends: {},
// 使用其它组件
components: {
'hm-login': HmLogin
},
data() {
},
computed: {
},
filters: {
},
created() {
},
methods: {}
}
</script>
<style scoped>
</style>
<template>
<div>
个人中心
</div>
</template>
<script>
export default {
name: 'login',
// 继承其他组件
extends: {},
// 使用其它组件
components: {
},
data() {
return {
}
},
computed: {
},
filters: {
},
created() {
},
methods: {}
}
</script>
<style scoped>
</style>
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -28,7 +28,8 @@ const sections = [
return [
'./src/views/haomo/components/tables/HmComplexTable.vue',
'./src/views/haomo/components/forms/HmComplexForm.vue',
'./src/views/haomo/components/details/HmComplexDetail.vue'
'./src/views/haomo/components/details/HmComplexDetail.vue',
'./src/views/haomo/components/panel/HmPanel.vue'
]
}
},
......
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