查看“︁JavaScript/页面引导”︁的源代码
来自康健生活
←
JavaScript/页面引导
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 引言 == == 页面新功能引导 == {{hc|head=pop.js|output=<syntaxhighlight lang="javascript"> /** * @description 绑定浏览器弹窗 * @author kangkk */ // import cookie from 'js-cookie'; import { POP_UP_PROJECT_DATA } from '../config/pop'; import { mustBeNumber } from './number'; /** * @function checkParamWithPop * @description 检查参数是否合法 * @param {string} _ - * @returns {boolean} */ const checkParamWithPop = _ => { if (!POP_UP_PROJECT_DATA[_]) throw new Error(`不合法的参数${_},在 config/pop.js 文件中检查参数设置`); }; /** * @function getDataWithPop * @description 获取弹窗参数 * @returns {object} 弹窗的值 */ export const getDataWithPop = _ => { const data = localStorage.getItem('pop-up-window') || {}; try { return typeof data === 'string' ? JSON.parse(data) : data; } catch { throw new Error(`pop-up-window 解析错误`); } }; /** * @function getTimeWithPop * @description 获取弹窗参数 * @param {string} _ - [POP_UP_PROJECT_DATA] 弹窗类型 * @returns {string|undefined} 弹窗类型的时间戳 */ export const getTimeWithPop = _ => { checkParamWithPop(_); return mustBeNumber(getDataWithPop()[_]); }; /** * @function setTimeWithPop * @description 设置弹窗参数 * @param {string} _ - [POP_UP_PROJECT_DATA] 弹窗类型 */ export const setTimeWithPop = _ => { checkParamWithPop(_); const data = getDataWithPop(); data[_] = new Date().getTime(); try { localStorage.setItem( 'pop-up-window', JSON.stringify(data) ); } catch { throw new Error(`设置 localStorage pop-up-window 错误`); } }; /** * @function switchModalWithPop * @description 是否打开引导弹窗 * @param {string} _ - [POP_UP_PROJECT_DATA] 弹窗类型 * @returns {boolean} */ export const switchModalWithPop = _ => { const time = getTimeWithPop(_); if (time && time >= POP_UP_PROJECT_DATA[_]) return false; return true; }; </syntaxhighlight>}}
此页面嵌入的页面:
模板:Hc
(
查看源代码
)
模板:Hc/style.css
(
查看源代码
)
返回
JavaScript/页面引导
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。