Ai
4 Star 4 Fork 5

WeiboGe2012/自动化测试平台vue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
util.js 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
WeiboGe2012 提交于 2020-12-31 11:16 +08:00 . 新增登录记住密码
// 引入Cookies
import Cookies from 'js-cookie'
/**
* 时间戳
* @param {*} timestamp 时间戳
*/
const timestampToTime = (timestamp) => {
const date = new Date(timestamp) // 时间戳为10位需*1000,时间戳为13位的话不需乘1000
const Y = date.getFullYear() + '-'
const M =
(date.getMonth() + 1 < 10
? '0' + (date.getMonth() + 1)
: date.getMonth() + 1) + '-'
const D =
(date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
const h =
(date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
const m =
(date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) +
':'
const s =
date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
return Y + M + D + h + m + s
}
/**
* 存储localStorage
*/
const setStore = (name, content) => {
if (!name) { return }
if (typeof content !== 'string') {
content = JSON.stringify(content)
}
window.localStorage.setItem(name, content)
}
/**
* 获取localStorage
*/
const getStore = (name) => {
if (!name) { return }
return window.localStorage.getItem(name)
}
/**
* 删除localStorage
*/
const removeStore = (name) => {
if (!name) { return }
window.localStorage.removeItem(name)
}
/**
* 设置cookie
**/
function setCookie (name, value, day) {
return Cookies.set(name, value, { expires: day })
}
/**
* 获取cookie
**/
function getCookie (name) {
return Cookies.get(name)
}
/**
* 删除cookie
**/
function delCookie (name) {
return Cookies.remove(name)
}
/**
* 导出
**/
export {
timestampToTime,
setStore,
getStore,
removeStore,
setCookie,
getCookie,
delCookie
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/WeiboGe2012/automated-test-platform-vue.git
git@gitee.com:WeiboGe2012/automated-test-platform-vue.git
WeiboGe2012
automated-test-platform-vue
自动化测试平台vue
master

搜索帮助