import moment from 'moment';
import { VNode } from 'vue';
import { Component, Prop, Vue } from 'vue-property-decorator';
import { CreateElement } from 'vue';
import { acc } from '@ibizstudio/api';
import './design-item-content.less';
@Component
export class DesignItemContent extends Vue {
/**
* 绘制类型
*
* @type {('item'|'other')}
* @memberof DesignItemContent
*/
@Prop()
renderType!: 'item' | 'other';
/**
* 数据
*
* @type {*}
* @memberof DesignItemContent
*/
@Prop()
data!: any;
/**
* 上下文
*
* @type {*}
* @memberof DesignItemContent
*/
@Prop()
ctx!: any;
/**
* 表单项标题宽度
*
* @type {number}
*/
formItemlabelWidth:number = 0;
/**
* acc 订阅标识
*
* @type {string[]}
* @memberof createPanelModal
*/
accSubs: string[] = [];
created() {
// 初始化获取表单项标签宽度
this.formItemlabelWidth = this.ctx.ctrl.formItemlabelWidth;
this.accSubs.push(
acc.commandLocal(
(data: any) => {
// 发生变化前与发生变化后的值进行对比
if (!Object.is(data.labelwidth,this.formItemlabelWidth)) {
this.formItemlabelWidth = data.labelwidth
}
},
'update',
'PSDEFORM',
),
);
}
/**
* 绘制函数
*
* @param {CreateElement} h
* @return {*}
* @memberof DesignItemContent
*/
render(h: CreateElement) {
return this.renderContent(h);
}
/**
* 绘制内容
*
* @param {CreateElement} h
* @return {*}
* @memberof DesignItemContent
*/
renderContent(h: CreateElement) {
// 当前项数据
const tag: any = this.data;
// 标签位置
const labelPos: string = tag.labelpos ? tag.labelpos.toLowerCase() : 'left';
// 标签样式
const labelStyle: string =
Object.is(labelPos, 'top') || Object.is(labelPos, 'bottom') ? '' : `width: ${tag.labelwidth || this.formItemlabelWidth || 130}px;`;
// // 编辑器样式
const ctrlStyle: string = this.getFormCtrlStyle(tag, labelPos);
if (tag.itemtype === 'FIELD') {
return (
);
}
if (this.renderType === 'item') {
return (
);
} else if (this.renderType === 'other') {
return this.renderDesignOtherItem();
}
return null;
}
/**
* @description 获取内容样式
* @param {*} data
* @return {*}
* @memberof DesignItemContent
*/
getContentStyle(data: any) {
if (data && data.rawcssstyle) {
const res = data.rawcssstyle.split("\n");
const target: string[] = [];
for (let i = 0; i < res.length; i++) {
target.push(...res[i].split(";").filter((value: string) => value));
}
return target.filter((value: string) => {
return value.split(":").length === 2;
}).join(";");
}
}
/**
* 获取表单控件样式
*
* @protected
* @param {*} tag
* @param {string} labelPos
* @returns {string}
* @memberof FormItem
*/
protected getFormCtrlStyle(tag: any, labelPos: string): string {
let style: string = '';
if (
Object.is(labelPos, 'none') ||
Object.is(labelPos, 'top') ||
Object.is(labelPos, 'bottom') ||
tag.showcaption == '0'
) {
if (tag.ctrlwidth) {
style += `width: ${tag.ctrlwidth}px;`;
} else {
style += `width: 100%;`;
}
} else {
if (tag.ctrlwidth) {
style += `width: ${tag.ctrlwidth}px;`;
} else {
style += `width: calc(100% - ${tag.labelwidth || 130}px);`;
}
}
if (tag.ctrlheight) {
style += `height: ${tag.ctrlheight}px;`;
} else {
style += `height: 100%;`;
}
return style;
}
/**
* 绘制项
*
* @param {PSDEFormDetail} data
* @return {*} {*}
* @memberof DesignItemContent
*/
public renderDesignItem(): any {
const data = this.data;
const contentStyle = this.getContentStyle(data);
const { text} = data;
const curDate = new Date();
const previewHtml = data.previewhtml;
if (previewHtml) {
this.$nextTick(() => {
const divRef = this.$refs[`${data.pssyseditorstyleid}`] as HTMLDivElement;
if (divRef) {
divRef.innerHTML = previewHtml;
}
});
return ;
}
if (data) {
switch (data.editortype) {
case 'HIDDEN':
return (
隐藏表单项
);
case 'SPAN':
return (
{text}
);
// case 'HTMLEDITOR':
// return {text}[HTML编辑框];
// case 'IPADDRESSTEXTBOX':
// return {text}[IP地址输入框];
// case 'CODEEIDT':
// return {text}[代码编辑器];
case 'RADIOBUTTONLIST':
return (
选项一
选项二
选项三
);
case 'ADDRESSPICKUP':
case 'ADDRESSPICKUP_AC':
return (
选项一
选项二
选项三
);
// case 'LISTBOX':
// return {text}[列表框];
// case 'LISTBOXPICKUP':
// return {text}[列表框(选择)];
case 'TEXTAREA':
return (
);
case 'TEXTAREA_10':
return ;
case 'PASSWORD':
return ;
case 'DATEPICKEREX':
return (
);
case 'DATEPICKEREX_MINUTE':
return (
);
case 'DATEPICKEREX_SECOND':
return (
);
case 'DATEPICKEREX_NODAY':
return ;
case 'DATEPICKEREX_NODAY_NOSECOND':
return ;
case 'DATEPICKEREX_NOTIME':
return (
);
case 'DATEPICKEREX_HOUR':
return (
);
case 'DATEPICKER':
return (
);
// case 'PICTURE':
// return {text}[图片控件];
// case 'PICTURE_ONE':
// return {text}[图片控件(单项)];
case 'TEXTBOX':
return ;
case 'FILEUPLOADER':
return (
{text}
);
case 'AC':
case 'AC_NOBUTTON':
case 'AC_FS_NOBUTTON':
case 'AC_FS':
case 'PICKEREX_LINKONLY':
case 'PICKER':
case 'PICKUPVIEW':
case 'PICKEREX_LINK':
case 'PICKEREX_NOAC_LINK':
case 'PICKEREX_NOAC':
case 'PICKEREX_NOBUTTON':
case 'PICKEREX_TRIGGER_LINK':
case 'PICKEREX_TRIGGER':
case 'DROPDOWNLIST':
return (
选项一
选项二
选项三
);
case 'MDROPDOWNLIST':
return (
选项一
选项二
选项三
);
case 'DROPDOWNLIST_100':
return (
选项一
选项二
选项三
);
case 'CHECKBOX':
return 选项;
case 'CHECKBOXLIST':
return ;
case 'NUMBER':
return ;
// case 'USERCONTROL':
// return {text}[用户自定义];
// case 'RAW':
// return {text}[直接内容];
case 'RATING':
return ;
case 'SLIDER':
return ;
case 'DATERANGE':
return (
);
case 'ARRAY':
return ;
case 'MAPPICKER':
return ;
case 'SWITCH':
return ;
}
}
return this.renderDefaultField();
}
/**
* @description 绘制默认属性
* @return {*}
* @memberof DesignItemContent
*/
protected renderDefaultField(): any {
const data = this.data;
const { text} = data;
return ;
}
/**
* 绘制项
*
* @param {*} data
* @return {*} {(VNode | null)}
* @memberof DesignItemContent
*/
public renderDesignOtherItem(): VNode | null {
const data = this.data;
switch (data.itemtype as any) {
// 直接内容
case 'RAWITEM':
return this.renderRawItem(data);
// 控件
case 'CONTROL':
return this.renderControl(data);
// 自定义部件
case 'USERCONTROL':
return this.renderUserControl(data);
// 按钮
case 'BUTTON':
return this.renderButton(data);
// 分页部件
case 'FORMPART':
return this.renderFormPart(data);
// 直接嵌入页面
case 'IFRAME':
return this.renderIframe(data);
// 复合表单项
case 'FORMITEMEX':
return this.renderDesignItemContentEx(data);
// 关系
case 'DRUIPART':
return this.renderDrUiPart(data);
// 控件占位
case 'CTRLPOS':
return this.renderCtrlPos(data);
// 嵌入视图
case 'APPVIEW':
return this.renderAppView(data);
// 快速菜单栏
case 'APPMENU':
return this.renderAppMenu(data);
// 系统门户部件
case 'SYSPORTLET':
return this.renderSysPortlet(data);
default:
return null;
}
}
/**
* 嵌入视图
*
* @param {*} data
* @return {*} {VNode}
* @memberof DesignItemContent
*/
private renderAppView(data: any): VNode {
return {data.text}-[嵌入视图];
}
/**
* 快速菜单栏
*
* @param {*} data
* @return {*} {VNode}
* @memberof DesignItemContent
*/
private renderAppMenu(data: any): VNode {
return {data.text}-[快速菜单栏];
}
/**
* 系统门户部件
*
* @param {*} data
* @return {*} {VNode}
* @memberof DesignItemContent
*/
private renderSysPortlet(data: any): VNode {
return {`${data.srftext} - [${data.title || '系统门户部件'}] `};
}
/**
* 布局容器
*
* @param {*} data
* @return {*} {VNode}
* @memberof DesignItemContent
*/
private renderContainer(data: any): VNode {
return {data.text}-[布局容器];
}
/**
* 控件
*
* @param {*} item
* @returns {VNode}
* @memberof DesignItemContent
*/
private renderControl(data: any): VNode {
return {data.text}-[控件];
}
/**
* 控件占位
*
* @param {*} item
* @memberof DesignItemContent
*/
protected renderCtrlPos(data: any): VNode {
return {data.text}-[控件占位];
}
/**
* 隐藏表单项
*
* @param {any} data
* @returns {*}
* @memberof DesignItemContent
*/
protected renderHiddenItem(data: any): any {
return {data.text}-[隐藏表单项]
;
}
/**
* 直接内容
*
* @param {*} item
* @memberof DesignItemContent
*/
protected renderRawItem(data: any): VNode {
return {data.text}[直接内容]
;
}
/**
* 自定义部件
*
* @param {*} item
* @memberof DesignItemContent
*/
protected renderUserControl(data: any): VNode {
return {data.text};
}
/**
* 按钮
*
* @param {*} item
* @memberof DesignItemContent
*/
protected renderButton(data: any): VNode {
const btnClass = data.detailstyle ? `ant-btn--${data.detailstyle.toLowerCase()}` : '';
const contentStyle = this.getContentStyle(data);
const text = data.showcaption != 0 ? data.text : '*';
if(data.rendermode=="LINK"){
//链接
return {text};
}else{
//按钮
return {text};
}
}
/**
* 表单部件
*
* @param {*} item
* @memberof DesignItemContent
*/
protected renderFormPart(data: any): VNode {
return {data.text}[表单部件]
;
}
/**
* 直接嵌入页面
*
* @param {*} item
* @returns {VNode}
* @memberof DesignItemContent
*/
protected renderIframe(data: any): VNode {
return {data.text}[直接嵌入页面(iframe)];
}
/**
* 复合表单项
*
* @param {*} item
* @returns {VNode}
* @memberof DesignItemContent
*/
protected renderDesignItemContentEx(data: any): VNode {
return {data.text}[复合表单项];
}
/**
* 关系
*
* @param {*} item
* @returns {VNode}
* @memberof DesignItemContent
*/
protected renderDrUiPart(data: any): VNode {
return {data.text}[关系];
}
destroyed(): void {
this.accSubs.forEach(sub => {
acc.unsubscribeLocal(sub);
});
}
}