<template>
  <div id="app-base-test-api">
    <div class="one-block-1">
      <span> 1. 测试一些操作系统api </span>
    </div>
    <div class="one-block-2">
      <a-space>
        <a-button @click="exec(1)"> 点击 </a-button>
        <a-button @click="exec2(1)"> 点击2 </a-button>
        <a-button @click="getMac()"> 获取mac 列表 </a-button>
        <a-button @click="getOSMessage()"> 获取系统信息 </a-button>
        <a-button @click="setSound()"> 设置声音50</a-button>
        <a-button @click="restart()">重启</a-button>
      </a-space>

      <a-space>
        <input v-model="progressName" placeholder="请输入进程名称" />
        <a-button @click="kill()"> kill 指定进程 </a-button>
      </a-space>
      <a-space>
        <input v-model="exePath" placeholder="请输入程序地址" />
        <a-button @click="starExe()"> 启动 </a-button>
      </a-space>
      <a-space>
        
        <a-button @click="testNet()"> 测试网络请求 </a-button>
      </a-space>
      <!-- <el-button type="danger">Danger</el-button> -->

      <!-- <a-space>
        <a-list size="small" bordered :data-source="iconData">
        <template #renderItem="{ item }">
          <a-list-item>
            <icon-font :type="item.type" style="font-size: 36px" />
          </a-list-item>
        </template>
      </a-list>
      </a-space> -->
    </div>
  </div>
</template>
<script>
import { ipcApiRoute } from "@/api/main";
import iconList from "@/utils/iconList";
import { ipc } from "@/utils/ipcRenderer";
import { apiBaseUrl , getDeviceHome} from "@/utils/api"
// 批量导入图片动态使用, 解决vite 无法动态图片的问题
const pngModules = import.meta.globEager("@/assets/*.png");
// 把所有的图片都返回了, 可以在 map 中做一些排序等操作,实现动态图片
const urls = Object.values(pngModules).map((mod) => mod.default);
export default {
  data() {
    return {
      type: 1,
      iconData: iconList,
      // 进程名称
      progressName: "",
      exePath: '',
    };
  },
  methods: {
    exec(id) {
      console.log("process:", process);
      const params = {
        id: id,
      };
      ipc.invoke(ipcApiRoute.test, params).then((res) => {
        console.log("res:", res);
      });
    },
    exec2(id) {
      //
    },
    getMac() {
      ipc.invoke(ipcApiRoute.getAllMac, {}).then((res) => {
        console.log("macs :", res);
      });
    },
    getOSMessage() {
      ipc.invoke(ipcApiRoute.getOSMessage, {}).then((res) => {
        console.log("OS :", res);
      });
    },
    setSound() {
      ipc.invoke(ipcApiRoute.deviceLoudness, { value: 100 }).then((res) => {
        console.log("设置后的声音 :", res);
      });
    },
    // 重启
    restart() {
      ipc.invoke(ipcApiRoute.deviceRestart, {}).then((res) => {
        console.log("重启 :", res);
      });
    },
    kill() {
      //deviceStarExe
      console.log(this.progressName);
      ipc.invoke(ipcApiRoute.deviceKillName, this.progressName).then((res) => {
        console.log("关闭进程结果 :", res);
      });
    },
    starExe(){
      console.log(this.exePath);
      ipc.invoke(ipcApiRoute.deviceStarExe, this.exePath).then((res) => {
        console.log("启动程序 :", res);
      });
    },
    testNet(){
      console.log(apiBaseUrl);
      getDeviceHome().then(response=>{
          console.log(response);
      }).catch(error => {
          console.error(error);
      });
    }
  },
};
</script>
<style lang="less" scoped>
#app-base-test-api {
  padding: 0px 10px;
  text-align: left;
  width: 100%;
  .one-block-1 {
    font-size: 16px;
    padding-top: 10px;
  }
  .one-block-2 {
    padding-top: 10px;
  }
}
</style>
