Live2d Test Env

兼容性复制功能/自定义mock数据/通用hook

*****自定义mock

const resourceList = computed(() =>
  Array.from({ length: 20 }, (_, index) => index).map((v, i) => {
    return 
       {
          id: i,
          joinList: Array.from({ length: i }, (_, index1) => index1).map(
            (v, index2) => `我真的想吃烧烤${index2}`
          ),
        } 
  })
);

*****通用复制功能

export const copyToClipboard = async (textToCopy) => {
  try {
    await navigator.clipboard.writeText(textToCopy);
    return Promise.resolve();
  } catch (err) {
    // 如果浏览器不支持Clipboard API,使用document.execCommand('copy')作为备选方案
    const textArea = document.createElement("textarea");
    textArea.value = textToCopy;
    document.body.appendChild(textArea);
    textArea.select();
    document.execCommand("copy");
    document.body.removeChild(textArea);
    return Promise.resolve();
  }
};

使用

const handleCopy = async ( ) => {  
  copyToClipboard(`
  我真的想吃烧烤: \n
  hhhhh
  `)
    .then(() => {
      Message.success(`复制成功`);
    })
    .catch((error) => {
      console.error("复制到剪贴板时出错:", error);
    });
};

当前时间
export const currentTime = () => {
  const currentDate = new Date();
  const currentYear = currentDate.getFullYear();
  const currentMonth = currentDate.getMonth() + 1; // 月份是从0开始的,所以要加1
  const currentDay = currentDate.getDate();
  const currentHour = currentDate.getHours();
  const currentMinute = currentDate.getMinutes();
  const currentSecond = currentDate.getSeconds();
  // 年月日时分秒
  const allTime = `${currentYear}-${currentMonth}-${currentDay} ${currentHour}:${currentMinute}:${currentSecond}`;
  const onlyToDay = `${currentYear}-${currentMonth}-${currentDay}`;
  const onlyToSecond = `${currentHour}:${currentMinute}:${currentSecond}`;
  return {
    currentYear,
    currentMonth,
    currentDay,
    currentHour,
    currentMinute,
    currentSecond,
    allTime,
    onlyToDay,
    onlyToSecond,
  };
};


posted @ 2023-12-13 14:59  致爱丽丝  阅读(9)  评论(0编辑  收藏  举报