debug
This commit is contained in:
239
code/public/template/shikong/huiyuan/js/public/api/fetch.js
Normal file
239
code/public/template/shikong/huiyuan/js/public/api/fetch.js
Normal file
@@ -0,0 +1,239 @@
|
||||
import { arrayBufferToBase64, layerPopup } from '../commonFun-news.js';
|
||||
import ConfigsJs from '../../class/config.js';
|
||||
import { storageObj } from '../localstorage.js';
|
||||
import EncAndDec from '../enc.js';
|
||||
|
||||
const Configs = new ConfigsJs();
|
||||
|
||||
const strApiDoMain = "https://hyapi.zzdaohang01.top"
|
||||
|
||||
export const strSite = 1
|
||||
|
||||
/**
|
||||
* fetchApi
|
||||
* @param {*} url
|
||||
* @param {*} data
|
||||
* @param {*} onSuccess
|
||||
* @param {*} onError
|
||||
* @param {*} loadingMessage
|
||||
*/
|
||||
export const fetchApi = function (url, data = null, onSuccess = null, onError = null, loadingMessage = '正在加载...') {
|
||||
|
||||
// 检测是否是 FormData,从而决定是否设置 'Content-Type' 为 'application/json'
|
||||
const isFormData = data instanceof FormData;
|
||||
|
||||
const headers = new Headers({
|
||||
'Accept': "application/x.hubserver.admin+json",
|
||||
'token': localStorage.getItem(storageObj.tokenKey)
|
||||
// 如果不是 FormData,设置 'Content-Type' 为 'application/json'
|
||||
});
|
||||
|
||||
if (!isFormData) {
|
||||
headers.append('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
let layerIndex = null;
|
||||
|
||||
const options = {
|
||||
method: data ? 'POST' : 'GET',
|
||||
headers,
|
||||
};
|
||||
|
||||
if (data) {
|
||||
options.body = isFormData ? data : JSON.stringify(data); // 如果是 FormData,则直接设置为 body
|
||||
}
|
||||
|
||||
// 显示加载提示
|
||||
function showLoading() {
|
||||
|
||||
if (loadingMessage) {
|
||||
layerIndex = layer.open({
|
||||
type: 2,
|
||||
content: loadingMessage // 修改这里以使用正确的变量
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭加载提示
|
||||
function closeLoading() {
|
||||
if (layerIndex !== null) {
|
||||
layer.close(layerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// 封装处理成功响应的逻辑
|
||||
function handleSuccessResponse(res) {
|
||||
// 解密处理
|
||||
// if (Configs.get('MIAO_API_ENCRYPT_STATUS') == '1') {
|
||||
// let returnENC = EncAndDec.decryptData(res, Configs.get('MIAO_API_ENCRYPT_KEY'));
|
||||
// res = JSON.parse(returnENC);
|
||||
// }
|
||||
if (res.code !== '000' && res.code != '015' && res.code != '014') {
|
||||
if(res.code != '014'){
|
||||
layerPopup(res.message,3);
|
||||
}
|
||||
// 重新登录
|
||||
if (res.code == '2000' || res.code == '995' || res.code == '996' || res.code == '992') {
|
||||
localStorage.setItem(storageObj.loginStatus, false)
|
||||
location.href = "/login"
|
||||
}
|
||||
|
||||
} else if (onSuccess) {
|
||||
onSuccess(res);
|
||||
}
|
||||
}
|
||||
|
||||
showLoading(); // 请求前显示加载提示
|
||||
|
||||
fetch(strApiDoMain+url, options)
|
||||
.then(response => {
|
||||
if(response.status == 204){
|
||||
return null ;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
// return response.text();
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
closeLoading(); // 请求成功,关闭加载提示
|
||||
if (typeof onSuccess === 'function') {
|
||||
handleSuccessResponse(data);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
closeLoading(); // 请求失败,关闭加载提示
|
||||
layerPopup(error,3);
|
||||
console.error('Fetch error:', error);
|
||||
if (typeof onError === 'function') {
|
||||
onError(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const asyncFunction = function (url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(url)
|
||||
.then((response) => response.arrayBuffer())
|
||||
.then((buffer) => {
|
||||
if (buffer) {
|
||||
buffer = buffer.slice(17, buffer.length);
|
||||
var imageStr = arrayBufferToBase64(buffer);
|
||||
resolve(imageStr);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
reject('异步操作失败');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 访问失败的回调函数
|
||||
*
|
||||
*/
|
||||
export const onError = function (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
|
||||
export const source = {
|
||||
url: "",
|
||||
type: 'POST',
|
||||
dataType: 'json', //预期的服务器响应的数据类型。
|
||||
processData: true, //布尔值,规定通过请求发送的数据是否转换为查询字符串。默认是 true。
|
||||
contentType: "application/x-www-form-urlencoded", //发送数据到服务器时所使用的内容类型。默认是:"application/x-www-form-urlencoded"。
|
||||
cache: true, //是否缓存被请求页面。默认是 true。
|
||||
async: true, //是否异步处理。默认是 true。
|
||||
data: {
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* post 请求
|
||||
* @param {*} source
|
||||
* @param {*} successFn
|
||||
* @param {*} errorFn
|
||||
* @param {*} loading
|
||||
* @param {*} from
|
||||
* 如果不要 loading ,可以设置为false,默认是“正在加载。。”
|
||||
* 如果需要表单上传,请设置from 为true ,默认为false,
|
||||
* 如果没有token,headers也可以注释
|
||||
* postFun(source, successFn, errorFn,loading='正在加载。。')
|
||||
*/
|
||||
export const postFun = function (source, successFn, errorFn, loading = '正在加载。。', from = false) {
|
||||
if (!source || !source.url) {
|
||||
console.error('Invalid source or URL');
|
||||
return;
|
||||
}
|
||||
|
||||
let layerIndex = null;
|
||||
|
||||
// 设置Ajax请求参数
|
||||
if (from) {
|
||||
source.processData = false;
|
||||
source.contentType = false;
|
||||
source.cache = false;
|
||||
}
|
||||
|
||||
// 显示加载层
|
||||
function showLoading() {
|
||||
if (loading !== false) {
|
||||
layerIndex = layer.open({
|
||||
type: 2,
|
||||
content: loading
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭加载层
|
||||
function closeLoading() {
|
||||
if (layerIndex !== null) {
|
||||
layer.close(layerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理成功响应
|
||||
function handleSuccessResponse(res) {
|
||||
// 解密处理
|
||||
if (Configs.get('MIAO_API_ENCRYPT_STATUS') == '1') {
|
||||
let returnENC = EncAndDec.decryptData(res, Configs.get('MIAO_API_ENCRYPT_KEY'));
|
||||
res = JSON.parse(returnENC);
|
||||
}
|
||||
if (res.code !== '000') {
|
||||
if (source.url === '/miao/pay/create') {
|
||||
res.msg = '当前支付通道拥堵,请更换其他支付通道支付。'
|
||||
}
|
||||
layerPopup(res.msg, 3);
|
||||
} else if (successFn) {
|
||||
successFn(res);
|
||||
}
|
||||
}
|
||||
|
||||
// 发起Ajax POST请求
|
||||
$.ajax({
|
||||
url: this.strApiDoMain + source.url,
|
||||
type: 'POST',
|
||||
data: source.data,
|
||||
dataType: source.dataType,
|
||||
async: source.async,
|
||||
headers: {
|
||||
'Accept': "application/x.hubserver.admin+json",
|
||||
'token': localStorage.getItem(storageObj.tokenKey)
|
||||
},
|
||||
beforeSend: showLoading,
|
||||
complete: closeLoading,
|
||||
success: handleSuccessResponse,
|
||||
error: function (e) {
|
||||
if (errorFn) errorFn(e);
|
||||
else console.error('AJAX request failed:', e);
|
||||
closeLoading();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
42
code/public/template/shikong/huiyuan/js/public/api/index.js
Normal file
42
code/public/template/shikong/huiyuan/js/public/api/index.js
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
|
||||
/**
|
||||
* api 接口
|
||||
*/
|
||||
export const apiGetUserInfo = '/api/user/info' //用户详情
|
||||
export const apiReGist = '/api/user/regist' //注册
|
||||
export const apiLoGout = '/api/user/logout'//退出
|
||||
export const apiLoginByEmail = '/api/user/login' //邮箱登录
|
||||
export const apiUserInfoSave = '/api/user/info/save' //修改密码
|
||||
|
||||
export const apiPayPackage = '/api/pay/package' //获取支付套餐
|
||||
export const apiPayChannele = '/api/pay/channel' //获取支付渠道
|
||||
export const apiPayOrderCreate = '/api/pay/order/create' //创建支付订单
|
||||
export const apiPayOrderList = '/api/pay/order/list' //获取充值订单列表
|
||||
export const apiFundsTransactionsList = '/api/funds/transactions/list' //获取交易流水
|
||||
|
||||
|
||||
export const resetPasswordByKey = '/miao/user/resetpwdbykey ' //根据key设置密码
|
||||
export const setPasswd = '/miao/user/setpasswd' //根据key设置密码
|
||||
export const apiGetVideoInfo = '/miao/video/info'//视频地址
|
||||
export const apiSaveStaTis = "/miao/statis/save" // 新统计api
|
||||
export const apiLoginByPhone = '/miao/user/phonelogin' //手机登录
|
||||
export const apiBindPhone = '/miao/user/bindphone' //绑定手机
|
||||
export const apiSmsCode = '/miao/user/smscode' //发送验证吗
|
||||
|
||||
export const apiRetrievePasswordByPhone = '/miao/user/retrievePasswordByPhone' //找回密码
|
||||
export const apiResetEmailByKey = '/miao/user/resetemailbykey' //绑定邮箱
|
||||
export const apiReGistByPhone = '/miao/user/registbyphone' //手机注册-
|
||||
export const apiReGistByEmail = '/miao/user/registbyemail' //邮箱注册-
|
||||
export const apiGetOrderList = '/miao/pay/orderlist'//支付订单列表
|
||||
export const apiGetFundsTransactionsList = '/miao/funds/transactions/list' //交易记录
|
||||
export const apiGetFundsInfo = '/miao/funds/info' //资金账户详情.md ok
|
||||
export const apiGetReferralList = '/miao/referral/list' //推广统计
|
||||
export const apiGetReferralShare = '/miao/referral/share' //推广链接
|
||||
export const apiFileUpdate = '/miao/file/upload'//反馈列表-上传
|
||||
export const apiFeedbackCreate = '/miao/feedback/create' //反馈列表--添加
|
||||
export const apiCheckReGist = '/miao/user/regist/check' //注册前置接口
|
||||
export const apiGetCaptcha = '/miao/user/captcha' //获取验证码
|
||||
export const apiGetFundsWithdrawalAccountList = '/miao/funds/withdrawal/account/list'//提现账户列表
|
||||
export const apiFundsWithdrawalOrderCreate = '/miao/funds/withdrawal/order/create' //申请提现
|
||||
export const apiGetFundsWithdrawalOrderList = '/miao/funds/withdrawal/order/list'//提现订单列表
|
||||
52
code/public/template/shikong/huiyuan/js/public/common.js
Normal file
52
code/public/template/shikong/huiyuan/js/public/common.js
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
import {
|
||||
checkIsLoginFn,
|
||||
hideCctvDomByEquipmentClass,
|
||||
intiHistoryHref,
|
||||
init,
|
||||
isSearchValid,
|
||||
pageJumpFn
|
||||
} from './commonFun.js';
|
||||
import CommonCctv from '../cctv/common.js';
|
||||
|
||||
/**
|
||||
* 所有页面调用的js
|
||||
*/
|
||||
const commonJs = function(){
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
hideCctvDomByEquipmentClass()
|
||||
intiHistoryHref()
|
||||
init()
|
||||
CommonCctv.init()
|
||||
|
||||
// 格式化轮播广告和 顶部导航的间隙
|
||||
function getHeaderHeight() {
|
||||
if(document.getElementById('header') && document.querySelector('.j-booth-elements-header')){
|
||||
var intHeaderHeight = document.getElementById('header').offsetHeight;
|
||||
document.querySelector('.j-booth-elements-header').style.height = intHeaderHeight + 'px';
|
||||
}
|
||||
}
|
||||
// 当窗口大小改变时调整高度
|
||||
window.onresize = getHeaderHeight();
|
||||
// 页面加载时调整高度
|
||||
window.onload = getHeaderHeight();
|
||||
})
|
||||
}()
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 会员 板块初始化
|
||||
*/
|
||||
const MenBerPublicJs = function () {
|
||||
const selectors = [
|
||||
".bill-web",".bind-web", ".buy-web", ".capital-flow-web", ".charge-web",".member-info-web",
|
||||
".recfeedback-web", ".setting-web",
|
||||
".withdrawal-funds-web", ".my-promotion-web",
|
||||
".withdrawal-records-web"
|
||||
];
|
||||
|
||||
if (selectors.some(selector => document.querySelector(selector))) {
|
||||
window.addEventListener('load', checkIsLoginFn);
|
||||
}
|
||||
}()
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* layer 弹窗提示
|
||||
* @param {string} strContent
|
||||
* @param int intTime
|
||||
*/
|
||||
export function layerPopup(strContent, intTime) {
|
||||
layer.open({
|
||||
shadeClose: false,
|
||||
skin: 'msg',
|
||||
content: strContent,
|
||||
time: intTime
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 将ArrayBuffer转换为Base64字符串
|
||||
* @param buffer buffer
|
||||
* @returns {string}
|
||||
*/
|
||||
export function arrayBufferToBase64(buffer) {
|
||||
let strBinary = '';
|
||||
const bytes = new Uint8Array(buffer);
|
||||
for (let i = 0; i < bytes.byteLength; i++) {
|
||||
strBinary += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return window.btoa(strBinary);
|
||||
}
|
||||
1329
code/public/template/shikong/huiyuan/js/public/commonFun.js
Normal file
1329
code/public/template/shikong/huiyuan/js/public/commonFun.js
Normal file
File diff suppressed because it is too large
Load Diff
88
code/public/template/shikong/huiyuan/js/public/enc.js
Normal file
88
code/public/template/shikong/huiyuan/js/public/enc.js
Normal file
@@ -0,0 +1,88 @@
|
||||
const EncAndDec = {
|
||||
|
||||
AesKey: 'QvanVezUfeJep0euYWZph4Dvq6zv5vKxNAwnfB6fyiY=',
|
||||
|
||||
/**
|
||||
* AES加密
|
||||
* @param {*} word 需要加解密的文本
|
||||
* @param {*} key 加解密的秘钥
|
||||
* iv: 偏移量,最短8位数,ECB模式不需要此参数
|
||||
* @returns
|
||||
*/
|
||||
// Encrypt(word, key = AesKey) {
|
||||
// let srcs = JSON.stringify(word);
|
||||
// let iv = crypto.randomBytes(16); // 16位的随机数
|
||||
// let cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv);
|
||||
// let encrypted = cipher.update(srcs);
|
||||
// encrypted = Buffer.concat([encrypted, cipher.final()]);
|
||||
// let ivBuffer = Buffer.from(iv, 'utf8');
|
||||
// let allBuffer = Buffer.concat([ivBuffer, encrypted]);
|
||||
// return allBuffer.toString('base64');
|
||||
// },
|
||||
|
||||
/**
|
||||
* AES解密
|
||||
* @param string word
|
||||
* @param string key
|
||||
* @returns string
|
||||
*/
|
||||
Decrypt(word = '', key = AesKey) {
|
||||
if (word.length == 0) return null
|
||||
let decodeBase64Str = atob(word)
|
||||
let signData = decodeBase64Str.slice(16);
|
||||
let encrypted = atob(signData);
|
||||
encrypted = JSON.parse(encrypted);
|
||||
const iv = CryptoJS.enc.Base64.parse(encrypted.iv);
|
||||
const value = encrypted.value;
|
||||
key = CryptoJS.enc.Base64.parse(key);
|
||||
var decrypted = CryptoJS.AES.decrypt(value, key, {
|
||||
iv: iv
|
||||
});
|
||||
decrypted = decrypted.toString(CryptoJS.enc.Utf8);
|
||||
return decrypted;
|
||||
},
|
||||
|
||||
decryptData(encryptedData, key) {
|
||||
// 将 Base64 编码的字符串转换为 WordArray
|
||||
const encryptedDataWA = CryptoJS.enc.Base64.parse(encryptedData);
|
||||
|
||||
// 提取 IV(初始化向量)。CryptoJS WordArray 对象的 sigBytes 属性表示字节数
|
||||
const iv = CryptoJS.lib.WordArray.create(encryptedDataWA.words.slice(0, 4), 16);
|
||||
|
||||
// 提取密文
|
||||
const ciphertext = CryptoJS.lib.WordArray.create(encryptedDataWA.words.slice(4), encryptedDataWA.sigBytes - 16);
|
||||
|
||||
// 转换密钥为 WordArray
|
||||
const keyWA = CryptoJS.enc.Utf8.parse(key);
|
||||
|
||||
// 解密
|
||||
const decrypted = CryptoJS.AES.decrypt({ ciphertext: ciphertext }, keyWA, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
});
|
||||
|
||||
// 将解密结果转换为 UTF8 字符串
|
||||
return decrypted.toString(CryptoJS.enc.Utf8);
|
||||
},
|
||||
|
||||
/**
|
||||
* 图片解密
|
||||
* @param string strImgBase64
|
||||
* @param object GetData
|
||||
* @returns string
|
||||
*/
|
||||
DecryptImg(strImgBase64, GetData) {
|
||||
let strBase64Content = `data:image/png;base64,${strImgBase64}`;
|
||||
let strImgId = "#" + GetData.id + ""
|
||||
let strImgUrl = $(strImgId).attr('data-original')
|
||||
if (strImgUrl == GetData.imgurl) {
|
||||
$(strImgId).attr('src', strBase64Content)
|
||||
$(strImgId).removeClass("jqlazyload");
|
||||
setImgHeightFun(strImgId)
|
||||
}
|
||||
return strBase64Content
|
||||
},
|
||||
}
|
||||
|
||||
export default EncAndDec
|
||||
102
code/public/template/shikong/huiyuan/js/public/head.js
Normal file
102
code/public/template/shikong/huiyuan/js/public/head.js
Normal file
@@ -0,0 +1,102 @@
|
||||
import { copyByInput,EnableFloatingWindowMovement } from './commonFun.js';
|
||||
|
||||
import {storageObj,getLoginStatus,getUserInfo} from './localstorage.js';
|
||||
|
||||
var HeadJs = function () {
|
||||
if (document.querySelector(".headjs")) {
|
||||
|
||||
if (getLoginStatus()) {
|
||||
|
||||
getHeadInfo()
|
||||
|
||||
} else {
|
||||
$('.user-is-login').hide()
|
||||
}
|
||||
|
||||
//用户详情
|
||||
function getHeadInfo() {
|
||||
|
||||
let userInfo = getUserInfo();
|
||||
|
||||
if (userInfo) {
|
||||
$('.user-no-login').hide();
|
||||
$('.is-login, .mm_name').show();
|
||||
|
||||
// 使用条件运算符简化文本设置逻辑
|
||||
let displayText = userInfo.mu_phone && userInfo.mu_phone.length > 5 ? userInfo.mu_phone : userInfo.mu_email;
|
||||
$('.mm_name').text(displayText);
|
||||
}
|
||||
}
|
||||
|
||||
//点击H5头部右边登录
|
||||
$("#go-login").on('click',function () {
|
||||
$(".user-hover").toggle();
|
||||
$('.mali-tips3').hide()
|
||||
$('.mali-tips').hide();
|
||||
$('.kong_back').hide();
|
||||
$('.kong_back3').hide();
|
||||
})
|
||||
|
||||
// 点击vip
|
||||
$(".vip-card-img").on('click',function () {
|
||||
$('#custom-dialog-ADO3').show();
|
||||
//lozyLoadFun(COVER_VERSION)
|
||||
});
|
||||
|
||||
// 点击 有些回复
|
||||
$(".mm_group_section .group-url").on('click',function () {
|
||||
$('.mali-tips').toggle();
|
||||
$('.kong_back3').toggle();
|
||||
});
|
||||
|
||||
// 点击商务合作
|
||||
$(".search_input_h5 .telegram-url").on('click',function () {
|
||||
$('.mali-tips3').addClass('mali-tips2');
|
||||
$('.mali-tips3').toggle();
|
||||
$('.kong_back').toggle();
|
||||
|
||||
$('.mali-tips').hide();
|
||||
$('.kong_back3').hide();
|
||||
|
||||
$(".user-hover").hide();
|
||||
});
|
||||
|
||||
// 点击空白处
|
||||
$(".kong_back").on('click',function () {
|
||||
$('.mali-tips3').toggle();
|
||||
$('.kong_back').toggle();
|
||||
});
|
||||
|
||||
// 点击空白处
|
||||
$(".kong_back3").on('click',function () {
|
||||
$('.mali-tips').toggle();
|
||||
$('.kong_back3').toggle();
|
||||
});
|
||||
|
||||
// 点击 复制 且隐藏
|
||||
$(".j-copy-an-hide-dom").on('click',function () {
|
||||
copyByInput($(this).attr("data-dom"))
|
||||
$(".user-hover").hide()
|
||||
$(".mali-tips").hide()
|
||||
})
|
||||
|
||||
// 点击 head 广告合作 且隐藏
|
||||
$('.j-head-telegram-click').on('click', function() {
|
||||
$(".user-hover").hide()
|
||||
$(".mali-tips").hide()
|
||||
});
|
||||
|
||||
// var wurl = window.location.host;
|
||||
|
||||
$('.header_title').text(document.domain);
|
||||
|
||||
function copySkipFun() {
|
||||
location.href = FOOTER_TELEGRAM_LINK
|
||||
}
|
||||
|
||||
EnableFloatingWindowMovement("#right-guide"); // 绑定到 #right-guide 元素
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
export default HeadJs
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
|
||||
//本地储存
|
||||
export const storageObj = {
|
||||
|
||||
loginStatus: window.location.hostname+'loginStatus', //登录状态
|
||||
|
||||
userInfo:window.location.hostname+'userInfo',
|
||||
|
||||
tokenKey : window.location.hostname+'mi_login_token', //token 本地储存key
|
||||
|
||||
isMember: window.location.hostname+'isMember', //是否会员 本地储存key
|
||||
|
||||
isBingPhoneReturn: window.location.hostname+'isBingPhoneReturn', //是否绑定手机页面返回
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录状态
|
||||
*/
|
||||
export function getLoginStatus() {
|
||||
|
||||
return localStorage.getItem(storageObj.loginStatus) || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会员信息
|
||||
*/
|
||||
export function getUserInfo() {
|
||||
|
||||
let userInfo = localStorage.getItem(storageObj.userInfo);
|
||||
// 如果 data 不为 null 且长度大于 0,解析 JSON,否则返回 null 或原始数据
|
||||
return userInfo && userInfo.length > 0 ? JSON.parse(userInfo) : userInfo;
|
||||
}
|
||||
|
||||
|
||||
330
code/public/template/shikong/huiyuan/js/public/request.js
Normal file
330
code/public/template/shikong/huiyuan/js/public/request.js
Normal file
@@ -0,0 +1,330 @@
|
||||
import { pageJumpFn, arrayBufferToBase64, layerPopup } from './commonFun.js';
|
||||
import ConfigsJs from '../class/config.js';
|
||||
import { storageObj } from './localstorage.js';
|
||||
const Configs = new ConfigsJs();
|
||||
console.log(Configs.get('API_DOMAIN'))
|
||||
/**
|
||||
* 获取api
|
||||
*/
|
||||
const requestJs = {
|
||||
strApiDoMain: Configs.get('API_DOMAIN'),
|
||||
//点击统计-base
|
||||
saveStaTis:"/miao/statis/save", // 新统计api
|
||||
//用户
|
||||
regist: '/miao/user/regist', //注册-
|
||||
registbyphone: '/miao/user/registbyphone', //手机注册-
|
||||
registbyemail: '/miao/user/registbyemail', //邮箱注册-
|
||||
emaillogin: '/miao/user/emaillogin', //邮箱登录-
|
||||
login: '/miao/user/login', //登录
|
||||
phonelogin: '/miao/user/phonelogin', //手机登录-
|
||||
retrievePasswordByPhone: '/miao/user/retrievePasswordByPhone', //找回密码-
|
||||
info: '/miao/user/info',//用户详情-
|
||||
smscode: '/miao/user/smscode',//发送验证吗-
|
||||
bindphone: '/miao/user/bindphone',//绑定手机-
|
||||
setpasswd: '/miao/user/setpasswd',//修改密码-
|
||||
logout: '/miao/user/logout',//推出-
|
||||
|
||||
channel: '/miao/pay/channel',//支付渠道
|
||||
create: '/miao/pay/create',//创建支付订单
|
||||
|
||||
channelV2: '/miao/pay/v2/channel',//获取支付通道列表V2-
|
||||
createV2: '/miao/pay/v2/create',//创建支付订单V2-
|
||||
|
||||
notify: '/miao/pay/notify',//支付异步回调
|
||||
orderlist: '/miao/pay/orderlist',//支付订单列表-
|
||||
packagevip: '/miao/pay/package',//获取套餐
|
||||
//视频
|
||||
videoinfo: '/miao/video/info',//视频地址
|
||||
//问题反馈
|
||||
feedbacklist: '/miao/feedback/index',//反馈列表
|
||||
feedbackcreate: '/miao/feedback/create',//反馈列表--添加-
|
||||
fileupdate: '/miao/file/upload',//反馈列表-上传-
|
||||
getVipTime: '/miao/pay/getVipTime',//涮新wip时间
|
||||
|
||||
|
||||
getFundsInfo: '/miao/funds/info',//资金账户详情.md ok-
|
||||
getFundsTransactionsList: '/miao/funds/transactions/list',//交易记录.md ok -
|
||||
getFundsWithdrawalAccountList: '/miao/funds/withdrawal/account/list',//提现账户列表.md-
|
||||
getFundsWithdrawalOrderList: '/miao/funds/withdrawal/order/list',//提现订单列表.md ok-
|
||||
getFundsWithdrawalOrderCreate: '/miao/funds/withdrawal/order/create',//申请提现.md-
|
||||
getFundsWithdrawalOrderPut: '/miao/funds/withdrawal/account/put',//设置提现账户.md
|
||||
getReferralList: '/miao/referral/list', //推广统计.md-
|
||||
getReferralShare: '/miao/referral/share', //推广链接-
|
||||
|
||||
checkregist: '/miao/user/regist/check', //注册前置接口-
|
||||
getcaptcha: '/miao/user/captcha',//获取验证码-
|
||||
|
||||
resetPasswordByKey:'/miao/user/resetPasswordByKey', //根据key设置密码
|
||||
|
||||
/**
|
||||
* 默认参数
|
||||
*/
|
||||
source: {
|
||||
url: "",
|
||||
type: 'POST',
|
||||
dataType: 'json', //预期的服务器响应的数据类型。
|
||||
processData: true, //布尔值,规定通过请求发送的数据是否转换为查询字符串。默认是 true。
|
||||
contentType: "application/x-www-form-urlencoded", //发送数据到服务器时所使用的内容类型。默认是:"application/x-www-form-urlencoded"。
|
||||
cache: true, //是否缓存被请求页面。默认是 true。
|
||||
async: true, //是否异步处理。默认是 true。
|
||||
data: {
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
//fetch
|
||||
fetchFun(url, data, callback, errFun) {
|
||||
fetch(url)
|
||||
.then((response) => response.arrayBuffer())
|
||||
.then((buffer) => {
|
||||
if (buffer) {
|
||||
buffer = buffer.slice(17, buffer.length);
|
||||
const imageStr = arrayBufferToBase64(buffer);
|
||||
callback(imageStr, data);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error)
|
||||
errFun(data)
|
||||
});
|
||||
},
|
||||
asyncFunction(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(url)
|
||||
.then((response) => response.arrayBuffer())
|
||||
.then((buffer) => {
|
||||
if (buffer) {
|
||||
buffer = buffer.slice(17, buffer.length);
|
||||
var imageStr = arrayBufferToBase64(buffer);
|
||||
resolve(imageStr);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
reject('异步操作失败');
|
||||
});
|
||||
});
|
||||
},
|
||||
asyncFunction2(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(url)
|
||||
.then((response) => response.arrayBuffer())
|
||||
.then((buffer) => {
|
||||
if (buffer) {
|
||||
var imageStr = arrayBufferToBase64(buffer);
|
||||
resolve(imageStr);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
reject('异步操作失败');
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
//原生请求-post
|
||||
ajaxPost(url, data, callback) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', url, true);
|
||||
xhr.setRequestHeader('accept', 'application/x.hubserver.admin+json');
|
||||
xhr.send(data);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
callback(xhr.responseText);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
//原生请求-get
|
||||
ajaxGet(url, data, callback, errFun) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.setRequestHeader('accept', 'application/x.hubserver.admin+json');
|
||||
xhr.send();
|
||||
xhr.onreadystatechange = function () {
|
||||
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
callback(xhr.responseText, data);
|
||||
}
|
||||
if (xhr.readyState == 4 && xhr.status == 0) {
|
||||
this.errFun(data)
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
//获取本地token
|
||||
getStorageToken(key) {
|
||||
var token = window.localStorage.getItem(key)
|
||||
if (!token) {
|
||||
return false
|
||||
}
|
||||
return token
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* post 请求
|
||||
* @param source 数据
|
||||
* @param successHandle 访问成功的回调函数
|
||||
* @param errorHandle 访问失败回调函数
|
||||
* 如果不要loding,可以设置为false,默认是“正在加载。。”
|
||||
* 如果需要表单上传,请设置from 为true ,默认为false,
|
||||
* 如果没有token,headers也可以注释
|
||||
* postFun(source, successfn, errorfn,loding='正在加载。。')
|
||||
*
|
||||
**/
|
||||
postFun: function (source, successfn, errorfn, loading = '正在加载。。', from = false) {
|
||||
let layerIndex = null;
|
||||
|
||||
// 设置Ajax请求参数
|
||||
if (from) {
|
||||
source['processData'] = false;
|
||||
source['contentType'] = false;
|
||||
source['cache'] = false;
|
||||
}
|
||||
|
||||
// 封装显示加载层的逻辑
|
||||
function showLoading() {
|
||||
if (loading !== false) {
|
||||
layerIndex = layer.open({
|
||||
type: 2,
|
||||
content: loading,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 封装关闭加载层的逻辑
|
||||
function closeLoading() {
|
||||
if (layerIndex !== null) {
|
||||
layer.close(layerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// 封装处理成功响应的逻辑
|
||||
function handleSuccessResponse(res) {
|
||||
// 解密处理
|
||||
if (Configs.get('MIAO_API_ENCRYPT_STATUS') == '1') {
|
||||
let returnENC = EncAndDec.decryptData(res, Configs.get('MIAO_API_ENCRYPT_KEY'));
|
||||
res = JSON.parse(returnENC);
|
||||
}
|
||||
if (res.code != '000') {
|
||||
if(source['url'] == '/miao/pay/create'){
|
||||
res.msg = '当前支付通道拥堵,请更换其他支付通道支付。'
|
||||
}
|
||||
|
||||
if(res.code != '014'){
|
||||
layerPopup(res.msg,3);
|
||||
}
|
||||
|
||||
// 重新登录
|
||||
if (res.code === '2000' || res.code === '995' || res.code === '996') {
|
||||
localStorage.setItem(storageObj.loginStatus, false)
|
||||
location.href = "/member/login.html"
|
||||
}
|
||||
}
|
||||
successfn(res);
|
||||
}
|
||||
|
||||
// 发起Ajax POST请求
|
||||
$.ajax({
|
||||
url: this.strApiDoMain + source['url'],
|
||||
type: 'POST',
|
||||
data: source['data'],
|
||||
dataType: source['dataType'],
|
||||
async: source['async'],
|
||||
headers: {
|
||||
'Accept': "application/x.hubserver.admin+json",
|
||||
'token': localStorage.getItem(storageObj.tokenKey)
|
||||
},
|
||||
beforeSend: showLoading,
|
||||
complete: closeLoading,
|
||||
success: handleSuccessResponse,
|
||||
error: function (e) {
|
||||
if (errorfn) errorfn(e);
|
||||
closeLoading();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* get 请求
|
||||
* @param source 数据
|
||||
* @param successHandle 访问成功的回调函数
|
||||
* @param errorHandle 访问失败回调函数
|
||||
* 如果不要loding,可以设置为false,默认是“正在加载。。”
|
||||
* 如果没有token,headers也可以注释
|
||||
* getFun(source, successfn, errorfn,loding='正在加载。。')
|
||||
*
|
||||
**/
|
||||
getFun: function (source, successFun, errorFun, loadingMessage = '正在加载...') {
|
||||
const layerIndex = loadingMessage !== false ? layer.open({ type: 2, content: loadingMessage }) : null;
|
||||
|
||||
$.ajax({
|
||||
url: this.strApiDoMain + source['url'],
|
||||
type: 'GET',
|
||||
dataType: source['dataType'],
|
||||
async: source['async'],
|
||||
headers: {
|
||||
'Accept': "application/x.hubserver.admin+json",
|
||||
'token': localStorage.getItem(storageObj.tokenKey)
|
||||
},
|
||||
beforeSend: function () {
|
||||
// 加载中的逻辑已经在外面处理
|
||||
},
|
||||
complete: function () {
|
||||
if (layerIndex !== null) {
|
||||
layer.close(layerIndex);
|
||||
}
|
||||
},
|
||||
success: function (res) {
|
||||
handleResponse(res); // 处理响应的逻辑可以抽取出来
|
||||
successFun(res); // 调用成功的回调函数
|
||||
},
|
||||
error: function (e) {
|
||||
if (errorFun) errorFun(e); // 只有在提供了错误回调函数的情况下才调用
|
||||
}
|
||||
});
|
||||
|
||||
// 处理响应逻辑
|
||||
function handleResponse(res) {
|
||||
// 解密处理
|
||||
if (Configs.get('MIAO_API_ENCRYPT_STATUS') == '1') {
|
||||
let returnENC = EncAndDec.decryptData(res, Configs.get('MIAO_API_ENCRYPT_KEY'));
|
||||
res = JSON.parse(returnENC);
|
||||
}
|
||||
if (['2000', '2002', '2003','995','996'].includes(res.code)) {
|
||||
localStorage.setItem(storageObj.loginStatus, false);
|
||||
localStorage.setItem(storageObj.isMember, false);
|
||||
localStorage.setItem(storageObj.tokenKey, '');
|
||||
localStorage.setItem(storageObj.userInfo, '');
|
||||
const redirectMap = {
|
||||
'995': '/member/login.html',
|
||||
'996': '/member/login.html',
|
||||
'2000': '/member/login.html',
|
||||
'2002': '/member/buy.html',
|
||||
'2003': '/home.html' // 假设这是视频不存在时的页面
|
||||
};
|
||||
pageJumpFn({ 'url': redirectMap[res.code], 'url_type': 1 });
|
||||
} else if (res.code != '000') {
|
||||
layerPopup(res.msg, 3);
|
||||
} else {
|
||||
//layerPopup(res.message, 3);
|
||||
// 处理其他code的逻辑,如果有必要
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* 访问失败的回调函数
|
||||
*
|
||||
*/
|
||||
errorfn(err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default requestJs;
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* simple-share
|
||||
* @yujiangshui
|
||||
* https://github.com/yujiangshui/simple-share.js
|
||||
*
|
||||
* Licensed under the MIT license.
|
||||
*/
|
||||
|
||||
var SimpleShare = function(options) {
|
||||
|
||||
// get share content
|
||||
options = options || {};
|
||||
var url = options.url || window.location.href;
|
||||
var title = options.title || document.title;
|
||||
var content = options.content || '';
|
||||
var pic = options.pic || '';
|
||||
|
||||
// fix content format
|
||||
url = encodeURIComponent(url);
|
||||
title = encodeURIComponent(title);
|
||||
content = encodeURIComponent(content);
|
||||
pic = encodeURIComponent(pic);
|
||||
|
||||
// share target url
|
||||
var qzone = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={url}&title={title}&pics={pic}&summary={content}';
|
||||
var weibo = 'http://service.weibo.com/share/share.php?url={url}&title={title}&pic={pic}&searchPic=false';
|
||||
var tqq = 'http://share.v.t.qq.com/index.php?c=share&a=index&url={url}&title={title}&appkey=801cf76d3cfc44ada52ec13114e84a96';
|
||||
var renren = 'http://widget.renren.com/dialog/share?resourceUrl={url}&srcUrl={url}&title={title}&description={content}';
|
||||
var douban = 'http://www.douban.com/share/service?href={url}&name={title}&text={content}&image={pic}';
|
||||
var facebook = 'https://www.facebook.com/sharer/sharer.php?u={url}&t={title}&pic={pic}';
|
||||
var twitter = 'https://twitter.com/intent/tweet?text={title}&url={url}';
|
||||
var linkedin = 'https://www.linkedin.com/shareArticle?title={title}&summary={content}&mini=true&url={url}&ro=true';
|
||||
var weixin = 'http://qr.liantu.com/api.php?text={url}';
|
||||
var qq = 'http://connect.qq.com/widget/shareqq/index.html?url={url}&desc={title}&pics={pic}';
|
||||
|
||||
// replace content functions
|
||||
function replaceAPI (api) {
|
||||
api = api.replace('{url}', url);
|
||||
api = api.replace('{title}', title);
|
||||
api = api.replace('{content}', content);
|
||||
api = api.replace('{pic}', pic);
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
// share target
|
||||
this.qzone = function() {
|
||||
window.open(replaceAPI(qzone));
|
||||
};
|
||||
this.weibo = function() {
|
||||
window.open(replaceAPI(weibo));
|
||||
};
|
||||
this.tqq = function() {
|
||||
window.open(replaceAPI(tqq));
|
||||
};
|
||||
this.renren = function() {
|
||||
window.open(replaceAPI(renren));
|
||||
};
|
||||
this.douban = function() {
|
||||
window.open(replaceAPI(douban));
|
||||
};
|
||||
this.facebook = function() {
|
||||
window.open(replaceAPI(facebook));
|
||||
};
|
||||
this.twitter = function() {
|
||||
window.open(replaceAPI(twitter));
|
||||
};
|
||||
this.linkedin = function() {
|
||||
window.open(replaceAPI(linkedin));
|
||||
};
|
||||
this.qq = function() {
|
||||
window.open(replaceAPI(qq));
|
||||
};
|
||||
this.weixin = function(callback) {
|
||||
if (!callback) {
|
||||
window.open(replaceAPI(weixin));
|
||||
}else{
|
||||
callback(replaceAPI(weixin));
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
347
code/public/template/shikong/huiyuan/js/public/time.js
Normal file
347
code/public/template/shikong/huiyuan/js/public/time.js
Normal file
@@ -0,0 +1,347 @@
|
||||
const gettime = {
|
||||
// 计算当前日期星座
|
||||
getHoroscope(date) {
|
||||
let c = ['摩羯', '水瓶', '双鱼', '白羊', '金牛', '双子', '巨蟹', '狮子', '处女', '天秤', '天蝎', '射手', '摩羯']
|
||||
date = new Date(date);
|
||||
let month = date.getMonth() + 1;
|
||||
let day = date.getDate();
|
||||
let startMonth = month - (day - 14 < '865778999988'.charAt(month));
|
||||
return c[startMonth] + '座';
|
||||
},
|
||||
// 计算指定时间与当前的时间差
|
||||
sumAge(data) {
|
||||
let dateBegin = new Date(data.replace(/-/g, "/"));
|
||||
let dateEnd = new Date(); //获取当前时间
|
||||
let dateDiff = dateEnd.getTime() - dateBegin.getTime(); //时间差的毫秒数
|
||||
let dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
|
||||
let leave1 = dateDiff % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
|
||||
let hours = Math.floor(leave1 / (3600 * 1000)) //计算出小时数
|
||||
//计算相差分钟数
|
||||
let leave2 = leave1 % (3600 * 1000) //计算小时数后剩余的毫秒数
|
||||
let minutes = Math.floor(leave2 / (60 * 1000)) //计算相差分钟数
|
||||
//计算相差秒数
|
||||
let leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
|
||||
let seconds = Math.round(leave3 / 1000)
|
||||
return dayDiff + "天 " + hours + "小时 ";
|
||||
},
|
||||
// 获取聊天时间(相差300s内的信息不会显示时间)
|
||||
getChatTime(v1, v2) {
|
||||
v1 = v1.toString().length < 13 ? v1 * 1000 : v1;
|
||||
v2 = v2.toString().length < 13 ? v2 * 1000 : v2;
|
||||
if (((parseInt(v1) - parseInt(v2)) / 1000) > 300) {
|
||||
return this.gettime(v1);
|
||||
}
|
||||
},
|
||||
// 人性化时间格式
|
||||
gettime(shorttime) {
|
||||
shorttime = shorttime.toString().length < 13 ? shorttime * 1000 : shorttime;
|
||||
let now = (new Date()).getTime();
|
||||
let cha = (now - parseInt(shorttime)) / 1000;
|
||||
|
||||
if (cha < 43200) {
|
||||
// 当天
|
||||
return this.dateFormat(new Date(shorttime), "{A} {t}:{ii}");
|
||||
} else if (cha < 518400) {
|
||||
// 隔天 显示日期+时间
|
||||
// return this.dateFormat(new Date(shorttime), "{Mon}月{DD}日 {A} {t}:{ii}");
|
||||
return this.dateFormat(new Date(shorttime), "{Mon}.{DD} {A} {t}:{ii}");
|
||||
} else {
|
||||
// 隔年 显示完整日期+时间
|
||||
return this.dateFormat(new Date(shorttime), "{Y}.{MM}.{DD} {A} {t}:{ii}");
|
||||
}
|
||||
},
|
||||
|
||||
//数字补零
|
||||
parseNumber(num) {
|
||||
return num < 10 ? "0" + num : num;
|
||||
},
|
||||
|
||||
dateFormat(date, formatStr) {
|
||||
let dateObj = {},
|
||||
rStr = /\{([^}]+)\}/,
|
||||
// mons = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
|
||||
mons = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
||||
|
||||
dateObj["Y"] = date.getFullYear();
|
||||
dateObj["M"] = date.getMonth() + 1;
|
||||
dateObj["MM"] = this.parseNumber(dateObj["M"]);
|
||||
dateObj["Mon"] = mons[dateObj['M'] - 1];
|
||||
dateObj["D"] = date.getDate();
|
||||
dateObj["DD"] = this.parseNumber(dateObj["D"]);
|
||||
dateObj["h"] = date.getHours();
|
||||
dateObj["hh"] = this.parseNumber(dateObj["h"]);
|
||||
dateObj["t"] = dateObj["h"] > 12 ? dateObj["h"] - 12 : dateObj["h"];
|
||||
dateObj["tt"] = this.parseNumber(dateObj["t"]);
|
||||
dateObj["A"] = dateObj["h"] > 12 ? '下午' : '上午';
|
||||
dateObj["i"] = date.getMinutes();
|
||||
dateObj["ii"] = this.parseNumber(dateObj["i"]);
|
||||
dateObj["s"] = date.getSeconds();
|
||||
dateObj["ss"] = this.parseNumber(dateObj["s"]);
|
||||
|
||||
while (rStr.test(formatStr)) {
|
||||
formatStr = formatStr.replace(rStr, dateObj[RegExp.$1]);
|
||||
}
|
||||
return formatStr;
|
||||
},
|
||||
// 日期转几分钟前、几小时前显示 datetime 格式为2019-11-22 12:23:59样式
|
||||
timeago(dateTimeStamp) { //dateTimeStamp是一个时间毫秒,注意时间戳是秒的形式,在这个毫秒的基础上除以1000,就是十位数的时间戳。13位数的都是时间毫秒。
|
||||
// var dateTimeStamp = new Date(datetime.replace(/ /, 'T')).getTime() - 8 * 60 * 60 * 1000; //这里要减去中国的时区8小时
|
||||
dateTimeStamp = dateTimeStamp.toString().length < 13 ? dateTimeStamp * 1000 : dateTimeStamp;
|
||||
var minute = 1000 * 60; //把分,时,天,周,半个月,一个月用毫秒表示
|
||||
var hour = minute * 60;
|
||||
var day = hour * 24;
|
||||
var week = day * 7;
|
||||
var halfamonth = day * 15;
|
||||
var month = day * 30;
|
||||
var now = new Date().getTime(); //获取当前时间毫秒
|
||||
var diffValue = now - dateTimeStamp; //时间差
|
||||
|
||||
if (diffValue < 0) {
|
||||
// console.log("diffValue<0", datetime, dateTimeStamp, now, diffValue);
|
||||
return '刚刚';
|
||||
}
|
||||
var minC = diffValue / minute; //计算时间差的分,时,天,周,月
|
||||
var hourC = diffValue / hour;
|
||||
var dayC = diffValue / day;
|
||||
var weekC = diffValue / week;
|
||||
var monthC = diffValue / month;
|
||||
var result = "2";
|
||||
if (monthC >= 1 && monthC <= 3) {
|
||||
result = " " + parseInt(monthC) + "月前"
|
||||
} else if (weekC >= 1 && weekC <= 3) {
|
||||
result = " " + parseInt(weekC) + "周前"
|
||||
} else if (dayC >= 1 && dayC <= 6) {
|
||||
result = " " + parseInt(dayC) + "天前"
|
||||
} else if (hourC >= 1 && hourC <= 23) {
|
||||
result = " " + parseInt(hourC) + "小时前"
|
||||
} else if (minC >= 1 && minC <= 59) {
|
||||
result = " " + parseInt(minC) + "分钟前"
|
||||
} else if (diffValue >= 0 && diffValue <= minute) {
|
||||
result = "刚刚"
|
||||
} else {
|
||||
var datetime = new Date();
|
||||
datetime.setTime(dateTimeStamp);
|
||||
var Nyear = datetime.getFullYear(); {}
|
||||
var Nmonth = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
|
||||
var Ndate = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
|
||||
var Nhour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
|
||||
var Nminute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
|
||||
var Nsecond = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
|
||||
result = Nyear + "-" + Nmonth + "-" + Ndate
|
||||
}
|
||||
return result;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据时间戳 转换时间格式 :
|
||||
* @param {Object} time2
|
||||
* @param {Object} type
|
||||
* type:1 2018-02-02
|
||||
* type:2 02月02日 12:30
|
||||
* type:3 2018-02-02 12:30:30
|
||||
* type:4 2018-02-02 12:30:30
|
||||
*/
|
||||
format(time2, type) {
|
||||
let time = new Date(time2)
|
||||
var y = time.getFullYear();
|
||||
var m = time.getMonth() + 1;
|
||||
var d = time.getDate();
|
||||
var h = time.getHours();
|
||||
var mm = time.getMinutes();
|
||||
var s = time.getSeconds();
|
||||
if (type == 0) {
|
||||
console.log(d)
|
||||
return this.parseNumber(d);
|
||||
} else if (type == 1) {
|
||||
return y + '-' + this.parseNumber(m) + '-' + this.parseNumber(d);
|
||||
} else if (type == 2) {
|
||||
return this.parseNumber(m) + '月' + this.parseNumber(d) + '日' + '\xa0\xa0\xa0' + this.parseNumber(h) + ':' + this.parseNumber(
|
||||
mm);
|
||||
} else if (type == 3) {
|
||||
return this.parseNumber(h) + ':' + this.parseNumber(mm) + ':' + this.parseNumber(s);
|
||||
} else if (type == 4) {
|
||||
return y + '/' + this.parseNumber(m) + '/' + this.parseNumber(d);
|
||||
}else if (type == 5) {
|
||||
return this.parseNumber(m) + '-' + this.parseNumber(d) + ' ' + this.parseNumber(h) + ':' + this.parseNumber(
|
||||
mm)
|
||||
}else if (type == 6) {
|
||||
return this.parseNumber(m) + '-' + this.parseNumber(d);
|
||||
}else if (type == 7) {
|
||||
return this.parseNumber(h) + ':' + this.parseNumber(mm);
|
||||
}else {
|
||||
return y + '-' + this.parseNumber(m) + '-' + this.parseNumber(d) + ' ' + this.parseNumber(h) + ':' + this.parseNumber(
|
||||
mm) + ':' + this.parseNumber(s);
|
||||
}
|
||||
},
|
||||
/* 获取当前时间戳
|
||||
*/
|
||||
nowTime() {
|
||||
let now = new Date().getTime() / 1000
|
||||
return Math.floor(now)
|
||||
},
|
||||
/* 获取当前时间戳之后的时间戳 -- 三分钟
|
||||
*/
|
||||
nowAfterTime(){
|
||||
let now = new Date();
|
||||
// let timestamp = Math.floor(now.getTime() / 1000 /60); // 除以1000可得到以秒为单位的时间戳,除以60转换为以分钟为单位的时间戳
|
||||
let timestamp = Math.floor(now.getTime() / 1000); // 除以1000可得到以秒为单位的时间戳,除以60转换为以分钟为单位的时间戳
|
||||
let threeTime = Number(localStorage.getItem('threeTi'));
|
||||
if(threeTime != null){
|
||||
let currentTimestamp = Math.floor(new Date().getTime() / 1000);
|
||||
if(currentTimestamp - threeTime > 180) {
|
||||
localStorage.setItem('threeTi',currentTimestamp)
|
||||
// console.log(currentTimestamp,'currentTimestamp');
|
||||
return currentTimestamp
|
||||
}else{
|
||||
// console.log(threeTime,'threeTime');
|
||||
return threeTime
|
||||
}
|
||||
}else{
|
||||
localStorage.setItem('threeTi',timestamp)
|
||||
return timestamp
|
||||
// console.log('首次获取');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} end 截止时间
|
||||
* setInterval(() => {
|
||||
Countdown(1646063999*1000)
|
||||
},1000);
|
||||
*/
|
||||
Countdown(end) {
|
||||
//获取当前时间
|
||||
var date = new Date();
|
||||
var now = date.getTime();
|
||||
|
||||
//时间差
|
||||
var leftTime = end-now;
|
||||
|
||||
//定义变量 d,h,m,s保存倒计时的时间
|
||||
// var d,h,m,s;
|
||||
// if (leftTime>=0) {
|
||||
// d = Math.floor(leftTime/1000/60/60/24);
|
||||
// h = Math.floor(leftTime/1000/60/60%24);
|
||||
// m = Math.floor(leftTime/1000/60%60);
|
||||
// s = Math.floor(leftTime/1000%60);
|
||||
// }
|
||||
let obj
|
||||
if (leftTime>=0) {
|
||||
obj = {
|
||||
'd':Math.floor(leftTime/1000/60/60/24),
|
||||
'h':Math.floor(leftTime/1000/60/60%24),
|
||||
'm':Math.floor(leftTime/1000/60%60),
|
||||
's':Math.floor(leftTime/1000%60),
|
||||
}
|
||||
}
|
||||
return obj?obj : false
|
||||
//递归每秒调用countTime方法,显示动态时间效果
|
||||
//setTimeout(countTime,1000);
|
||||
|
||||
} ,
|
||||
|
||||
/**
|
||||
* @param {Object} Number
|
||||
* 秒转为 00:00:00
|
||||
*/
|
||||
s_format_hms(Number) {
|
||||
let s = parseInt(Number)
|
||||
let m = s / 60;
|
||||
let h = m / 60;
|
||||
return this.parseNumber(Math.floor(h)) + ':' + this.parseNumber(Math.floor(m)) + ':' + this.parseNumber(Math.floor(s))
|
||||
},
|
||||
|
||||
/**
|
||||
* 倒计时输出
|
||||
*
|
||||
*/
|
||||
getRestTime(time){
|
||||
var setTime = time;
|
||||
var nowTime = new Date();
|
||||
var restSec = setTime - nowTime.getTime();
|
||||
var day = parseInt(restSec / (60*60*24*1000));
|
||||
var hour = parseInt(restSec / (60*60*1000) % 24);
|
||||
var min = parseInt(restSec / (60*1000) % 60);
|
||||
var sec = parseInt(restSec / 1000 % 60);
|
||||
let obj = {
|
||||
'd':this.parseNumber(day),
|
||||
'h':this.parseNumber(hour),
|
||||
'm':this.parseNumber(min),
|
||||
's':this.parseNumber(sec),
|
||||
}
|
||||
return obj
|
||||
// return `剩余${day}天${hour}时${min}分${sec}秒`
|
||||
},
|
||||
//毫秒转 日时分秒
|
||||
TimeFramtHms(time){
|
||||
var day = parseInt(time / (60*60*24*1000));
|
||||
var hour = parseInt(time / (60*60*1000) % 24);
|
||||
var min = parseInt(time / (60*1000) % 60);
|
||||
var sec = parseInt(time / 1000 % 60);
|
||||
let obj = {
|
||||
'd':this.parseNumber(day),
|
||||
'h':this.parseNumber(hour),
|
||||
'm':this.parseNumber(min),
|
||||
's':this.parseNumber(sec),
|
||||
}
|
||||
return obj
|
||||
// return `剩余${day}天${hour}时${min}分${sec}秒`
|
||||
},
|
||||
//moap
|
||||
secTotime(s) {
|
||||
var t = '';
|
||||
if(s > -1){
|
||||
var hour = Math.floor(s/3600)
|
||||
var min = Math.floor(s/60) % 60
|
||||
var sec = s % 60
|
||||
if(hour < 10) {
|
||||
t = '0'+ hour + ":"
|
||||
} else {
|
||||
t = hour + ":"
|
||||
}
|
||||
if(min < 10){
|
||||
t += "0"
|
||||
}
|
||||
t += min + ":"
|
||||
if(sec < 10){
|
||||
t += "0"
|
||||
}
|
||||
t += sec.toFixed(2)
|
||||
}
|
||||
return t
|
||||
},
|
||||
// 视频长度格式化 1356 转 00:00:00
|
||||
changetime(value) {
|
||||
var secondTime = parseInt(value);// 秒
|
||||
var minuteTime = 0;// 分
|
||||
var hourTime = 0;// 小时
|
||||
if(secondTime > 60) {//如果秒数大于60,将秒数转换成整数
|
||||
//获取分钟,除以60取整数,得到整数分钟
|
||||
minuteTime = parseInt(secondTime / 60);
|
||||
//获取秒数,秒数取佘,得到整数秒数
|
||||
secondTime = parseInt(secondTime % 60);
|
||||
//如果分钟大于60,将分钟转换成小时
|
||||
if(minuteTime > 60) {
|
||||
//获取小时,获取分钟除以60,得到整数小时
|
||||
hourTime = parseInt(minuteTime / 60);
|
||||
//获取小时后取佘的分,获取分钟除以60取佘的分
|
||||
minuteTime = parseInt(minuteTime % 60);
|
||||
}
|
||||
}
|
||||
var time = "" + parseInt(secondTime) + "";
|
||||
|
||||
if(minuteTime > 0) {
|
||||
time = "" + parseInt(minuteTime) + ":" + time;
|
||||
}
|
||||
if(hourTime > 0) {
|
||||
time = "" + parseInt(hourTime) + ":" + time;
|
||||
}
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default gettime;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user