<template>
  <div>
    <BizTable
      ref="bt"
      :formatCol="formatCol"
      metaName="app_info"
      packageName="common"
      isMulti
      :refvalidatemethod2="validatemethod"
      @onexec="onexec"
    ></BizTable>
  </div>
</template>
  <script>
import BizTable from "../components/tables/biztables";
export default {
  name: "appinfo_page",
  data() {
    return {};
  },
  components: {
    BizTable
  },
  methods: {
    onexec(k,row){
   
    },
    validatemethod(rule, value, callback) {
      if(rule.field=="functionJSON"){
        try{
         let j= JSON.parse(value)
         console.log(j)
        }catch(e){
          return callback(new Error(e))
        }
      }
      if (rule.field == "hosts") {
        let attrhosts = value.split(",");
        if (attrhosts.length == 0) {
          callback(new Error("多个域名需要以逗号分隔"));
        }
      }
      if (rule.field == "paths") {
        let attrpaths = value.split(",");
        if (attrpaths.length == 0) {
          callback(new Error("多个路径需要以逗号分隔"));
        }else{
          attrpaths.forEach(p=>{
            if(!p.startsWith("/")){
               return callback(new Error("路径必须以/开始"))
            }
          })
        }
      }
      return callback();
    },
    // onnew() {
    //   this.$refs.bt.setFormCtlVisable("userName", true);
    // },
    // onedit() {
    //   this.$refs.bt.setFormCtlVisable("userName", false);
    // },
    formatCol(row, key, index) {
      // if (key == "roleName") {
      //   let rolestr = row.Roles.map(item => item.name).join(",");
      //   row.roles = row.Roles.map(item => item.id);
      //   return `<span>${rolestr}</span>`;
      // }
      // if (key == "isAdmin" || key == "isSuper") {
      //   return `<span>${row[key] ? "是" : "否"}</span>`;
      // }
      if (key == "created_at") {
        return `<span>${new Date(row[key]).toLocaleString()}</span>`;
      }
      return row[key];
    }
  }
};
</script>
  <style>
</style>
