kdesign-ui
Version:
kd is from company of klx, it provide quickly genarator company inner business front structure
73 lines (72 loc) • 4.31 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var index_1 = require("./index");
var babel = require('../babel');
var GenerateComTpl = /** @class */ (function (_super) {
tslib_1.__extends(GenerateComTpl, _super);
function GenerateComTpl(name, props) {
var _this = _super.call(this) || this;
_this.CODE = "";
_this.COMPOSE = {};
_this.TPL = "\n<Modal\n ref=\"Modal\"\n v-model=\"value\"\n :title=\"title\"\n :size=\"size\">\n <Layout>\n <FormLayout>\n <Form>\n <Row>\n <Col\n :md=\"8\"\n :sm=\"8\"\n :lg=\"8\"\n :key=\"$index\"\n v-for=\"(item, $index) in formConfig\">\n <FormItem\n :label=\"item.label\"\n :prop=\"item.key\">\n <Input\n v-if=\"item.type === 'Input'\"\n v-model=\"item[item.key]\" />\n <DatePicker\n v-else-if=\"item.type === 'DatePicker'\"\n v-model=\"item[item.key]\"></DatePicker>\n <Select\n v-else-if=\"item.type === 'Select'\"\n v-model=\"item[item.key]\">\n <Option\n :key=\"idx\"\n v-for=\"(opt, idx) in item.optionList\"\n :value=\"opt.value\">{{opt.label}}</Option>\n </Select>\n </FormItem>\n </Col>\n </Row>\n </Form>\n </FormLayout>\n </Layout>\n</Modal>\n ";
//生成组件
_this.CODE = _this.composeCode(_this.generate(name, props));
return _this;
}
GenerateComTpl.prototype.generate = function (name, props) {
return this.TPL;
};
GenerateComTpl.prototype.generateModal = function () {
};
GenerateComTpl.prototype.generateLayout = function () {
};
GenerateComTpl.prototype.generateForm = function () {
};
return GenerateComTpl;
}(index_1.GenerateTpl));
var GenerateComJs = /** @class */ (function (_super) {
tslib_1.__extends(GenerateComJs, _super);
function GenerateComJs(options) {
var _this = _super.call(this) || this;
_this.CODE = '';
_this.TPL = "\n /* eslint-disable */\n import Modal from '@/components/modal'\n import FormLayout from '@/components/layout/form-layout/form-layout'\n import Layout from '@/components/modal/layout'\n export default {\n data () {\n return {}\n },\n components: {\n Modal,\n Layout,\n FormLayout\n },\n methods: {\n open (type, title) {\n this.value = true\n this.title = title\n this.$methods('Modal', 'open')\n },\n close () {\n this.$methods('Modal', 'close')\n }\n }\n }";
_this.CODE = _this.composeCode(_this.generate(options));
return _this;
}
GenerateComJs.prototype.generate = function (options) {
return babel(this.TPL, {
visitor: function (t, babylon) {
return {
ReturnStatement: function (path) {
if (path.node.leadingComments)
return;
var newBlockStatement = t.returnStatement(babylon.parseExpression(JSON.stringify(options.data)));
path.replaceWith(newBlockStatement);
}
};
},
lintCode: function (code) {
return code.replace(/data\(\) \{/, 'data () {').replace(/\"/g, '\'');
}
});
};
return GenerateComJs;
}(index_1.GenerateJs));
var GenerateComStyle = /** @class */ (function (_super) {
tslib_1.__extends(GenerateComStyle, _super);
function GenerateComStyle(name) {
return _super.call(this) || this;
}
return GenerateComStyle;
}(index_1.GenerateStyle));
module.exports = function (props) {
if (props === void 0) { props = {}; }
var name = 'modal';
var tpl = new GenerateComTpl(name, props);
var js = new GenerateComJs({
data: props
});
var style = new GenerateComStyle(name);
return tpl.CODE + js.CODE + style.CODE;
};