js 程式碼生成器
<template>
<div id="wrapper">
<el-form ref="factory" :model="factory" :rules="rules" label-width="80px">
<el-form-item label="型別" prop="type">
<el-radio-group v-model="factory.type">
<el-radio label="Xml"></el-radio>
<el-radio label="Bean"></el-radio>
<el-radio label="Params"></el-radio>
<el-radio label="VO"></el-radio>
<el-radio label="Dao"></el-radio>
<el-radio label="DaoImpl"></el-radio>
<el-radio label="Service"></el-radio>
<el-radio label="ServiceImpl"></el-radio>
<el-radio label="Controller"></el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="名稱" prop="name">
<el-input v-model="factory.name"></el-input>
</el-form-item>
<el-form-item label="包名" prop="package" v-if="factory.type == 'Xml' ">
<el-input v-model="factory.package"></el-input>
</el-form-item>
<el-form-item label="欄位" prop="columns">
<el-input type="textarea" v-model="factory.columns" :autosize="{ minRows: 10, maxRows: 10}"></el-input>
</el-form-item>
<el-form-item label="輸出">
<el-input type="textarea" v-model="factory.output" :autosize="{ minRows: 15, maxRows: 15}"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submit('factory')">確定</el-button>
<el-button @click="reset">清空</el-button>
</el-form-item>
</el-form>
</div>
</template>
<script>
export default {
data() {
return {
factory: {
type: '',
name: '',
package: '',
columns: '',
output: '',
},
property: {
'xml':
`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="{0}">
<resultMap type="{1}" id="{2}">\n{3}
</resultMap>
<sql id="columns">{4}
</sql>
</mapper>`,
'int': 'int',
'varchar': 'String',
'tinyint': 'int',
'datetime': 'Date'
},
rules: {
type: [
{ required: true, message: '請選擇型別', trigger: 'change' }
],
name: [
{ required: true, message: '請輸入名稱', trigger: 'blur' },
],
package: [
{ required: true, message: '請輸入包名', trigger: 'blur' },
],
columns: [
{ required: true, message: '請輸入欄位', trigger: 'blur' },
],
},
}
},
methods: {
submit(formName) {
this.$refs[formName].validate((valid) => { // 校驗
if (valid) {
this.run(this.factory.type);
} else {
return false;
}
});
},
run(n) { // 執行
switch (n) {
case 'Xml':
var namespace = this.capitalize(this.factory.name, 'U');
var type = this.factory.package + "." + namespace;
var id = this.capitalize(namespace, 'L');
var columns = [];
var columnsList = this.factory.columns.split('\n').map(function (item) {
item = item.split('\t');
columns.push(item[0]);
var column = this.camelCase(item[0].substring(1).toLowerCase());
var property = this.property[item[1]];
var result = '\t\t<result column="{0}" property="{1}" />\n'.format(column, property);
return result;
}, this);
var result = this.strip(columnsList.join(''));
var output = this.property['xml'].format(namespace, type, id, result, columns.join(','));
this.factory.output = output;
break;
case 'Bean':
console.log('bean')
break;
case 'Params':
console.log('Params')
break;
case 'VO':
console.log('VO')
break;
case 'Dao':
console.log('Dao')
break;
case 'DaoImpl':
console.log('DaoImpl')
break;
case 'Service':
console.log('Service')
break;
case 'ServiceImpl':
console.log('ServiceImpl')
break;
case 'Controller':
console.log('Controller')
break;
}
},
reset() { // 重置
this.factory.name = '';
this.factory.columns = '';
this.factory.output = '';
this.factory.package = '';
},
capitalize(str, type) { // 首字元大寫
str = str.toLowerCase();
if (type == 'L') {
return str.replace(/\b(\w)|\s(\w)/g, function (m) {
return m.toLowerCase();
});
}
if (type == 'U') {
return str.replace(/\b(\w)|\s(\w)/g, function (m) {
return m.toUpperCase();
});
}
},
camelCase(str) { // 駝峰命名法
if (str.indexOf('_') > 0) {
str = str.split('_')[0] + this.capitalize(str.split('_')[1], 'U');
}
return str;
},
strip(str) {
return str.replace(/^\n+|\n+$/g, "");
},
}
}
</script>
關注我的技術公眾號《漫談人工智慧》,每天推送優質文章
相關文章
- js簡單程式碼生成器JS
- 使用 Node.js 寫一個程式碼生成器Node.js
- (程式碼生成)JS寫的程式碼生成器-編碼也可以這麼爽..JS
- 程式碼生成器
- Laravel 程式碼生成器Laravel
- ZT 程式碼生成器
- go模板-程式碼生成器Go
- MyBatis Plus程式碼生成器MyBatis
- Osiris-Team/jSQL-Gen:Java SQL (JDBC) 程式碼生成器JSSQLJavaJDBC
- SpringBoot程式碼生成器Spring Boot
- beego 程式碼自動生成器Go
- C#垃圾程式碼生成器C#
- PHP程式碼生成器介紹PHP
- 尋找Java程式碼生成器Java
- 動軟程式碼生成器學習
- mybatis_plus程式碼生成器類MyBatis
- Cruddiy:無程式碼Bootstrap CRUD生成器boot
- MyBatis-Plus之程式碼生成器MyBatis
- java 程式碼生成器設計方案Java
- 【風雲】也談程式碼生成器
- MyBatis程式碼生成器的實用MyBatis
- JNPF低程式碼開發框架程式碼 生成器設計框架
- ListCode增刪改查程式碼生成器-支援java、php、python、nodejsJavaPHPPythonNodeJS
- SpringBoot程式碼生成器,從此不用手擼程式碼Spring Boot
- 依賴注入工具程式碼生成器 wire依賴注入
- 程式碼生成器專案架構圖架構
- mybatis-generator-程式碼自動生成器MyBatis
- 又一款低程式碼生成器
- js程式碼JS
- Laravel 程式碼生成器 + 可深度定製模板Laravel
- 寫一個簡單的程式碼生成器
- Mybatis自動程式碼生成器的實現MyBatis
- 企業級java程式碼生成器MagicalCoderJava
- Mybatis-plus程式碼生成器的實現MyBatis
- chrome外掛: yapi 介面TypeScript程式碼生成器ChromeAPITypeScript
- hd-cg輝度通用程式碼生成器
- 10個便利的CSS程式碼線上生成器CSS
- 程式碼生成器Sql Server 和 Mysql 資料庫指令碼ServerMySql資料庫指令碼