app-column-format.vue 1.2 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
<template>
  <div class="app-column-format">
      {{text}}
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop, Model, Emit, Watch } from "vue-property-decorator";

/**
 * 表格列格式化json数组,数据格式为"[{"srfkey":"001","srfmajortext":"TEST1"},{"srfkey":"002","srfmajortext":"TEST2"}......]"
 */
@Component({
})
export default class AppColumnFormat extends Vue {
    
    /**
     * 值
     * @type {any}
     * @memberof AppColumnFormat
     */
    @Prop() public value?: any;

    /**
     * 显示文本
     * @type {any}
     * @memberof AppColumnFormat
     */
    get text(){
      if(this.value){
        let returnStr:string = "";
        let tempData:Array<any> =[];
        if(typeof(this.value) === 'string'){
          tempData= JSON.parse(this.value);
        }else{
          tempData = JSON.parse(JSON.stringify(this.value));
        }
        tempData.forEach((item:any,index:number) =>{
          if(index >0){
            returnStr +="、";
          }
          returnStr +=item.srfmajortext;
        })
        return returnStr;
      }else{
        return "";
      }
    }




}
</script>

<style lang='less'>
@import "./app-column-format.less";
</style>