// 是否是移动端
export const isMobile = () => {
  let flag = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
    navigator.userAgent
  )
  return flag
}

// 获取末尾补齐数
export const getFillNums = (selectorName, list, width) => {
  return new Promise((resolve) => {
    const target = document.querySelector(selectorName)
    if (!target) {
      // 如果节点还没有挂载，100ms后再尝试
      setTimeout(() => {
        return getFillNums(selectorName, list, width)
      }, 100)
    } else {
      const clientWidth = target.clientWidth
      // 每行最多有几个
      const rowMaxNum = Math.floor(clientWidth / width)
      resolve(list.length % rowMaxNum === 0 ? 0 : rowMaxNum - (list.length % rowMaxNum))
    }
  })
}
