Created
October 22, 2016 01:36
-
-
Save yanlee26/554e4452bbd58549cf03da10ac88cd65 to your computer and use it in GitHub Desktop.
test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="Content-type" content="text/html,charset=utf-8"/> | |
<meta http-equiv="X-UA-Compatible" content="IE-edge"> | |
<meta name="viewport" content="width=device-width,initial-scale=1"> | |
<link href="css/mui.min.css" rel="stylesheet"> | |
<link href="css/app.css" rel="stylesheet"> | |
<!--<script src="js/zepto.js" type="text/javascript"></script>--> | |
<script src="js/vue.js" type="text/javascript"></script> | |
<!--<script src="js/json2.js" type="text/javascript"></script>--> | |
<!--<script src="js/fuhao.js" type="text/javascript"></script>--> | |
<script src="js/fuhao-event.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<div id="main" class="mui-content"> | |
</div> | |
</body> | |
<script src="js/fuhao-components.js" type="text/javascript"></script> | |
<script> | |
(function () { | |
var jsonData = [ | |
{ | |
"keyname": "姓名鄂然失色而热热热热是重中之重重中之重重中之重杂志的热热", | |
"type": "text", | |
"key": "name11" | |
}, { | |
"value": "姓名鄂之重杂志的热热", | |
"key": "name11" | |
}, { | |
"keyname": "姓名鄂然失色而热热热热是重中之重重中之重重中之重杂志的热热", | |
}, | |
{ | |
"keyname": "姓名鄂然失色而热热热热是重中之重重中之重重中之重杂志的热热", | |
"type": "textarea", | |
"key": "name" | |
}, | |
{ | |
"keyname": "性别", | |
"type": "radio", | |
"key": "sex", | |
"values": [ | |
{ | |
"key": "man", | |
"value": "男辅导班" | |
}, | |
{ | |
"key": "women", | |
"value": "女" | |
} | |
] | |
}, | |
{ | |
"keyname": "复选", | |
"type": "checkbox", | |
"key": "checkbox", | |
"values": [ | |
{ | |
"key": "man", | |
"value": "男" | |
}, | |
{ | |
"key": "women", | |
"value": "女" | |
} | |
] | |
}, | |
{ | |
"keyname": "类型", | |
"type": "select", | |
"key": "type1", | |
"values": [ | |
{ | |
"key": "type1", | |
"value": "类型1" | |
}, | |
{ | |
"key": "type2", | |
"value": "类型2" | |
}, | |
{ | |
"key": "type3", | |
"value": "类型3" | |
}, | |
{ | |
"key": "type4", | |
"value": "类型4" | |
} | |
] | |
}, | |
{ | |
"keyname": "定位", | |
"type": "gps", | |
"key": "btn", | |
"value": "地图获取定位" | |
}, | |
{ | |
"keyname": "拍照", | |
"type": "photo", | |
"key": "btn", | |
"value": "拍照" | |
} | |
]; | |
AnalyJson(jsonData); | |
function AnalyJson(data) { | |
if ('id' in data) { | |
arguments.callee(data.values); | |
} else { | |
if ('name' in data) { | |
htmlname = data.name; | |
CreateInputViewer(data.name); | |
arguments.callee(data.values); | |
} else { | |
if ('type' in data) { | |
CreateInputViewer(data); | |
} else { | |
for (var p in data) { | |
CreateInputViewer(data[p]); | |
} | |
} | |
} | |
} | |
} | |
function CreateInputViewer(data) { | |
switch (data.type) { | |
case 'text': { | |
fh_C(data, 'c-input-text' + '-' + data.key, 'fhInputText', textTpl); | |
break; | |
} | |
case 'textarea': { | |
fh_C(data, 'c-textarea' + '-' + data.key, 'fhInputTextarea', textareaTpl); | |
break; | |
} | |
case 'radio': { | |
fh_C(data, 'c-input-radio' + '-' + data.key, 'fhInputTextarea', radioTpl); | |
break; | |
} | |
case 'checkbox': { | |
fh_C(data, 'c-input-checkbox' + '-' + data.key, 'fhInputCheckbox', checkboxTpl); | |
break; | |
} | |
case 'select': { | |
fh_C(data, 'c-select' + '-' + data.key, 'fhSelect', selectTpl); | |
break; | |
} | |
case 'photo': { | |
fh_C(data, 'c-photo' + '-' + data.key, 'fhPhoto', photoTpl); | |
break; | |
} | |
case 'gps': { | |
fh_C(data, 'c-gps' + '-' + data.key, 'fhGPS', gpsTpl); | |
break; | |
} | |
default: { | |
fh_C(data, 'c-default' + '-' + data.key, 'fhInputDefault', defaultTpl); | |
break; | |
} | |
} | |
} | |
function fh_C(d, c, cn, tpl) { | |
console.log(d); | |
Vue.component(c, { | |
template: tpl, | |
// props:['key','keyname','values','value'], | |
data: function () { | |
return d | |
} | |
}); | |
new Vue({ | |
el: '.mui-content', | |
components: { | |
cn: cn | |
}, | |
}); | |
var MyElementProto = Object.create(HTMLElement.prototype); | |
MyElementProto.createdCallback = function () { | |
this.innerHTML = tpl | |
}; | |
var MyComponent = document.registerElement(c, {prototype: MyElementProto}); | |
document.querySelector('.mui-content').appendChild(new MyComponent()); | |
} | |
})(); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment