index.vue 3.37 KB
Newer Older
1 2
<template>
  <!-- 自定义列表 -->
李嘉林 committed
3 4 5
  <div class="customList" v-if="loaded && comDataList.length>0" :style="{'padding':padding+'px','margin': margin+'px','border-radius': borderRadius + 'px','background':backgroundColor}">
    <div v-for="(item,index) in comDataList" :key="index" @click="itemClick(item,index)">
      <rich-text :nodes="item.comStr"></rich-text>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
function compiler(str, data) {
  //正则表达式  .+匹配{{}}所有字符 ?取消贪婪  g全局
  let regulation = /\{\{(.+?)\}\}/g;
  str = str.replace(regulation, function (_, val) {
    let key = val.trim();
    //调用 对象嵌套函数
    let value = data[key];
    return value;
  });
  return str;
}
import Vue from "vue";
李嘉林 committed
23
import index from "@/api/index";
24
const app = getApp()
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
export default {
  name: "custom-list",
  props: {
    render: {
      type: Boolean,
      default: false,
    },
    datas: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
李嘉林 committed
40 41 42
    return {
      loaded: false,
    };
43
  },
李嘉林 committed
44 45 46 47 48 49 50
  watch: {
    datas(newVal,oldVal) {
      if (newVal) {
        this.getList()
      }
    }
  },
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  computed:{
    comStr(){
      return compiler(this.datas.componentData.comStr,this.datas.componentData.comData);
    },
    padding() {
      return this.datas.componentData.padding;
    },
    margin() {
      return this.datas.componentData.margin;
    },
    borderRadius() {
      return this.datas.componentData.borderRadius;
    },
    backgroundColor() {
      return this.datas.componentData.backgroundColor;
    },
李嘉林 committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    showCont() {
      return this.datas.componentData.showCont;
    },
    dataSourceObj() {
      return this.datas.componentData.dataSourceObj;
    },
    comDataList: {
      get() {
        return this.datas.componentData.comDataList || [];
      },
      set(newValue) {
        this.datas.componentData.comDataList = newValue;
      },
    },
  },
  created() {
    this.getList();
84 85 86
  },
  mounted() {},
  methods:{
李嘉林 committed
87 88 89 90 91
    itemClick(item, index) {
      console.log(item,'--------------81')
      if (!item.bid) {
        return;
      }
92 93 94
      let paper = {
        bid : item.bid
      }
95
      let link = 'https://dk.taokor.cn/wchat/?token=${token}&scene=sso&toAppid=qOAhsauSaagQlxYdGbJL#/appraisalTwo?paper='+ encodeURIComponent(JSON.stringify(paper)) + `&mixid=${this.$store.state.mixid}`;
96 97 98 99 100 101 102 103
      console.log(link,'---link')
      app.$themeToLink({
        link : link,
        key: "1.5",
        name: link,
        type: 1.2,
      });
      // eval(this.datas.componentData.comMethods)
李嘉林 committed
104 105 106 107 108 109 110
    },
    getList(){
      let query = {
        ...this.dataSourceObj,
        current: 1,
        size: this.showCont,
      }
李嘉林 committed
111
      console.log(query,'------getList-----query')
李嘉林 committed
112 113
      index.outDataSourceData(query).then(res=>{
        if(res.data.code == 200){
李嘉林 committed
114
          this.comDataList = res.data.data.data || [];
李嘉林 committed
115
          this.comDataList = this.comDataList.slice(0,this.showCont);
李嘉林 committed
116 117 118 119 120 121 122 123 124 125 126
          if(this.comDataList && this.comDataList.length>0){
            this.comDataList.forEach((item,index)=>{
              item.comStr = compiler(this.datas.componentData.comStr,item);
            })
          }
        }
        this.loaded = true;
      })
    },
    getComStr(item){
      compiler(this.datas.componentData.comStr,item);
李嘉林 committed
127
    }
128 129 130 131 132 133 134 135 136
  },
  components: {},
};
</script>

<style lang="scss" scoped>
.customList {
}
</style>