diff --git a/src/views/haomo/components/details/HmComplexDetail.vue b/src/views/haomo/components/details/HmComplexDetail.vue index 55abddf52e97dd209b48bd6a565cd03faf2e4a51..d7d11c636aa46295f7340802d2187626149fd90e 100644 --- a/src/views/haomo/components/details/HmComplexDetail.vue +++ b/src/views/haomo/components/details/HmComplexDetail.vue @@ -32,6 +32,32 @@ 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用æ¥å¸¦å‡ºç”¨æˆ·ä¿¡æ¯ * */ @@ -52,17 +78,51 @@ filters: { }, created() { - this.init() this.getList() + this.init() }, methods: { - init() { + validate() { const self = this - _.each(self.schema['columns'], function(column) { - const tmp = JSON.parse(JSON.stringify(column)) - self.showColumns.push(tmp) - }) + // 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 + console.log(self.schema); + // 处ç†è¦æ˜¾ç¤ºçš„列 + 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' } diff --git a/src/views/haomo/components/details/index.vue b/src/views/haomo/components/details/index.vue index 1fd4a705274888749a97055a3ca89a981c0afea6..86493bfc79f580c14e9f26087a44bd8fd72256fc 100644 --- a/src/views/haomo/components/details/index.vue +++ b/src/views/haomo/components/details/index.vue @@ -1,6 +1,6 @@ <template> <div> - <hm-complex-detail :schema="schema['HmUser']" :userId="userId"> + <hm-complex-detail :schema="schema['HmUser']" :userId="userId" :columns="showUserColumns"> </hm-complex-detail> </div> </template> @@ -18,7 +18,9 @@ 'hm-complex-detail': HmComplexDetail }, data() { - return {} + return { + showUserColumns: ['mobile', 'loginid'] + } }, computed: { },