<template>
  <div
		class="commonfunctions-card"
  >
    <div class="click-area" @click="gotoQuery(item)">
      <div class="icon">
        <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
          <title>{{item.function.title}}</title>
          <use :xlink:href="`${item.icon}`"></use>
        </svg>
      </div>
      <div class="title">
        {{item.function.title}}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    item: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      sqlResult: 0,
    }
  },
  methods: {
    async gotoQuery(item) {
      if (!item.function || !item.function.id) return
      function getUUID() {
        return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
          var r = (Math.random() * 16) | 0,
            v = c == "x" ? r : (r & 0x3) | 0x8;
          return v.toString(16);
        });
      }
      item = item.function
      let appConfig = await window.GMS.util.nvwa.getAppConfig(item.id)
      appConfig = appConfig?.data?.configJson || '{}'
      appConfig = JSON.parse(appConfig)
      if (
        window.osConfig.appOpenMode &&
        window.osConfig.appOpenMode == "apploader"
      ) {
        window.GMS.$hideContainer.$portalAPI.emit(
          "open-new-page", //打开一个新的页签
          getUUID(),
          item.appName,
          {
            ...appConfig,
          },
          {
            openWay: "FUNCTAB",
            title: item.title,
          }
        );
      } else {
        if (item.path) {
          window.GMS.$hideContainer.$router.push({
            path: `/${item.path}`
          })
          return
        }
        const [appName, moduleName] = item.appName.split('/')
        const portalConfig = { id: item.id }
        if (moduleName) {
          portalConfig['exportLibrary'] = moduleName
          portalConfig['funcName'] = moduleName
        }
        const path = window.GMS.routerManager.getRouter().resolve({
          name: "app",
          query: {
            name: appName,
            "os-jump": encodeURIComponent(window.Base64.encode(JSON.stringify(
              Object.assign(
                {  },
                portalConfig
              )
            ))),
            onlyShowContent: false,
          }
        })
        window.location.hash = path.href
        setTimeout(() => {
          window.location.hash = '#'
        }, 0);
        setTimeout(() => {
          sessionStorage.setItem('appObj', '')
        }, 3500);
      }
		},
  },
  created() {
  },
}
</script>

<style scoped lang="less">
.commonfunctions-card {
  height: 118px;
  background: #FFFFFF;
  padding: 24px 16px 16px 16px; 
  font-family: PingFangSC-Regular, PingFang SC;
  .click-area {
    height: 100%;
    width: fit-content;
    margin: 0 auto;
    cursor: pointer;
    .icon {
      width: 46px;
      height: 46px;
      margin: 0 auto 12px auto;
      svg {
        width: 100%;
        height: 100%;
      }
    }
    .title {
      height: 20px;
      font-size: 14px;
      font-weight: 400;
      color: #424242;
      line-height: 20px;
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}
</style>