%APP_CODELIST%.ts.ftl 10.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<#ibiztemplate>
TARGET=PSAPPCODELIST
</#ibiztemplate>
<#if item.getCodeListType() == "DYNAMIC"> 
<#if item.getPSAppDataEntity?? && item.getPSAppDataEntity()??>
import ${srfclassname('${item.getPSAppDataEntity().codeName}')}Service from '@service/${srffilepath2(item.getPSAppDataEntity().codeName)}/${srffilepath2(item.getPSAppDataEntity().codeName)}-service';
</#if>
/**
 * 代码表--${item.getName()}
 *
 * @export
 * @class ${srfclassname('${item.getCodeName()}')}
 */
export default class ${srfclassname('${item.getCodeName()}')} {

    /**
     * 是否启用缓存
     *
     * @type boolean
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public isEnableCache:boolean = ${item.isEnableCache()?c};

24
    /**
25
     * 过期时间
26
     *
27
     * @type any
28 29
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
30
    public static expirationTime:any;
31

32
    /**
33
     * 预定义类型
34
     *
35
     * @type string
36 37
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
38
    public predefinedType:string ='<#if item.getPredefinedType?? && item.getPredefinedType()??>${item.getPredefinedType()}</#if>';
39

40
    /**
41
     * 缓存超长时长
42 43 44 45
     *
     * @type any
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
46
    public cacheTimeout:any = ${item.getCacheTimeout()?c};
47

48 49 50 51 52 53 54 55 56 57
    /**
     * 代码表模型对象
     *
     * @type any
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public codelistModel:any = {
        codelistid:"${item.getCodeName()}"
    };

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    /**
     * 获取过期时间
     *
     * @type any
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public getExpirationTime(){
        return ${srfclassname('${item.getCodeName()}')}.expirationTime;
    }

    /**
     * 设置过期时间
     *
     * @type any
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public setExpirationTime(value:any){
        ${srfclassname('${item.getCodeName()}')}.expirationTime = value; 
    }

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    /**
     * 自定义参数集合
     *
     * @type any
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public userParamNames:any ={
        <#if item.getUserParamNames()??>
        <#list item.getUserParamNames() as paramName>
        ${paramName}:"${item.getUserParam(paramName)}"<#if paramName_has_next>,</#if>
        </#list>
        </#if>
    }

    /**
     * 查询参数集合
     *
     * @type any
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public queryParamNames:any ={
        <#if item.getMinorSortDir()?? && item.getMinorSortPSAppDEField()??>
        sort: '${item.getMinorSortPSAppDEField().getCodeName()?lower_case},${item.getMinorSortDir()?lower_case}'
        </#if>
    }

<#if item.getPSAppDataEntity?? && item.getPSAppDataEntity()??>
    /**
     * ${item.getPSAppDataEntity().getLogicName()}应用实体服务对象
     *
     * @type {${srfclassname('${item.getPSAppDataEntity().codeName}')}Service}
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public ${item.getPSAppDataEntity().codeName?lower_case}Service: ${srfclassname('${item.getPSAppDataEntity().codeName}')}Service = new ${srfclassname('${item.getPSAppDataEntity().codeName}')}Service();
</#if>

<#-- 不为子系统代码表 -->
<#if item.isSubSysCodeList() == false>
<#if item.getPSAppDataEntity?? && item.getPSAppDataEntity()?? && item.getPSAppDEDataSet?? && item.getPSAppDEDataSet()??> 

    /**
     * 处理数据
     *
121
     * @public
122 123 124 125
     * @param {any[]} items
     * @returns {any[]}
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
126
    public doItems(items: any[]): any[] {
127
        let _items: any[] = [];
128 129 130 131 132 133 134
        if(items && items instanceof Array && items.length >0){
            items.forEach((item: any) => {
                let itemdata:any = {};
                Object.assign(itemdata,{id:item.<#if item.getValuePSAppDEField()??>${item.getValuePSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getKeyPSAppDEField().codeName?lower_case}</#if>});
                Object.assign(itemdata,{value:item.<#if item.getValuePSAppDEField()??>${item.getValuePSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getKeyPSAppDEField().codeName?lower_case}</#if>});
                Object.assign(itemdata,{text:item.<#if item.getTextPSAppDEField()??>${item.getTextPSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getMajorPSAppDEField().codeName?lower_case}</#if>});
                Object.assign(itemdata,{label:item.<#if item.getTextPSAppDEField()??>${item.getTextPSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getMajorPSAppDEField().codeName?lower_case}</#if>});
135
                <#if item.getDisablePSDEField()??>Object.assign(itemdata,{disabled:item.${item.getDisablePSDEField().getCodeName()?lower_case}? false : true});</#if>
136
                <#if item.getPValuePSAppDEField()??>Object.assign(itemdata,{pvalue:item.${item.getPValuePSAppDEField().getCodeName()?lower_case}});</#if>
137 138
                <#if item.getIconPathPSDEField()??>Object.assign(itemdata,{icon:item.${item.getIconPathPSDEField().getCodeName()?lower_case}});</#if>
                <#if item.getIconClsPSDEField()??>Object.assign(itemdata,{iconcls:item.${item.getIconClsPSDEField().getCodeName()?lower_case}});</#if>
139 140 141
                _items.push(itemdata);
            });
        }
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
        return _items;
    }

    /**
     * 获取数据项
     *
     * @param {*} context
     * @param {*} data
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public getItems(context: any={}, data: any={}, isloading?: boolean): Promise<any> {
        return new Promise((resolve, reject) => {
            data = this.handleQueryParam(data);
            const promise: Promise<any> = this.${item.getPSAppDataEntity().codeName?lower_case}Service.${item.getPSAppDEDataSet().codeName}(context, data, isloading);
            promise.then((response: any) => {
                if (response && response.status === 200) {
                    const data =  response.data;
                    resolve(this.doItems(data));
                } else {
                    resolve([]);
                }
            }).catch((response: any) => {
                console.error(response);
                reject(response);
            });
        });
    }
    <#else>

    /**
     * 获取数据项
     *
     * @param {*} data
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public getItems(data: any={}, isloading?: boolean): Promise<any> {
        return Promise.reject([]);
    }
    </#if>
    <#else>
    <#if item.getPSAppDataEntity?? && item.getPSAppDataEntity()?? && item.getPSAppDEDataSet?? && item.getPSAppDEDataSet()??> 

    /**
     * 获取数据项
     *
     * @param {string} context 
     * @param {*} data
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public getItems(context:any = {}, data: any={}, isloading?: boolean): Promise<any> {
        return new Promise((resolve, reject) => {
            data = this.handleQueryParam(data);
            const promise: Promise<any> = this.${item.getPSAppDataEntity().codeName?lower_case}Service.${item.getPSAppDEDataSet().codeName}(context, data, isloading);
            promise.then((response: any) => {
                if (response && response.status === 200) {
                    const data =  response.data;
                    resolve(this.doItems(data));
                } else {
                    resolve([]);
                }
            }).catch((response: any) => {
                console.error(response);
                reject(response);
            });
        });
    }

    /**
     * 处理数据
     *
218
     * @public
219 220 221 222
     * @param {any[]} items
     * @returns {any[]}
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
223
    public doItems(items: any[]): any[] {
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
        let _items: any[] = [];
        items.forEach((item: any) => {
            let itemdata:any = {};
            Object.assign(itemdata,{id:item.<#if item.getValuePSAppDEField()??>${item.getValuePSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getKeyPSAppDEField().codeName?lower_case}</#if>});
            Object.assign(itemdata,{value:item.<#if item.getValuePSAppDEField()??>${item.getValuePSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getKeyPSAppDEField().codeName?lower_case}</#if>});
            Object.assign(itemdata,{text:item.<#if item.getTextPSAppDEField()??>${item.getTextPSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getMajorPSAppDEField().codeName?lower_case}</#if>});
            <#if item.getPValuePSAppDEField()??>Object.assign(itemdata,{pvalue:item.${item.getPValuePSAppDEField().getCodeName()?lower_case}});</#if>
            _items.push(itemdata);
        });
        return _items;
    }
    <#else>

    /**
     * 获取数据项
     *
     * @param {string} context 
     * @param {*} data
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public getItems(context:any = {}, data: any={}, isloading?: boolean): Promise<any> {
        return Promise.reject([]);
    }    
    </#if>    
    </#if>

    /**
     * 处理查询参数
     * @param data 传入data
     * @memberof ${srfclassname('${item.getCodeName()}')}
     */
    public handleQueryParam(data:any){
        let tempData:any = data?JSON.parse(JSON.stringify(data)):{};
        if(this.userParamNames && Object.keys(this.userParamNames).length >0){
            Object.keys(this.userParamNames).forEach((name: string) => {
                if (!name) {
                    return;
                }
                let value: string | null = this.userParamNames[name];
                if (value && value.startsWith('%') && value.endsWith('%')) {
                    const key = value.substring(1, value.length - 1);
                    if (this.codelistModel && this.codelistModel.hasOwnProperty(key)) {
                        value = (this.codelistModel[key] !== null && this.codelistModel[key] !== undefined) ? this.codelistModel[key] : null;
                    } else {
                        value = null;
                    }
                }
                Object.assign(tempData, { [name]: value });
            });
        }
        Object.assign(tempData,{page: 0, size: 1000});
        if(this.queryParamNames && Object.keys(this.queryParamNames).length > 0){
            Object.assign(tempData,this.queryParamNames);
        }
        return tempData;
    }
}
</#if>