const b64 = require('b64.js')
const formatTime = date => {
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
return [month, day].map(formatNumber).join('/') + ' ' + [hour, minute].map(formatNumber).join(':')
}
const prettyTime = date => {
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
return month + '月' + day + '日 ' + [hour, minute].map(formatNumber).join(':')
}
const prettyTimeYMD = date => {
const month = date.getMonth() + 1
const day = date.getDate()
return month + '月' + day + '日 '
}
const minute = 1000 * 60;
const hour = minute * 60;
const day = hour * 24;
const week = day * 7;
const halfamonth = day * 15;
const month = day * 30;
const agoTime = dateTimeStamp => {
var now = new Date().getTime();
var diffValue = now - dateTimeStamp;
var v = 0
var result = ""
if ((v = diffValue/month) >= 1) {
if (v >= 3) {
result = "3 个月前"
} else {
result = "" + (v|0) + " 月前"
}
} else if ((v = diffValue/week) >= 1) {
result = "" + (v|0) + " 周前"
} else if ((v = diffValue/day) >= 1) {
result = "" + (v|0) + " 天前"
} else if ((v = diffValue/hour) >= 1) {
result = "" + (v|0) + " 小时前"
} else if ((v = diffValue/minute) >= 1) {
result = "" + (v|0) + " 分钟前"
} else {
result = "刚刚"
}
return result
}
const msgTime = (date) => {
const month = date.getMonth() + 1
const _day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
var now = new Date().getTime();
var diffValue = now - date;
if (diffValue/day >= 1) {
return [month, _day].map(formatNumber).join('-')
} else {
return [hour, minute].map(formatNumber).join(': ')
}
}
const getDaysFromNow = (created_at) => {
var thatTime = new Date(created_at * 1000)
var nowTime = new Date()
return Math.ceil((nowTime - thatTime) / (1000 * 3600 * 24))
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
// 从当前页面传递数据到上一个页面
function setResult(data) {
const pages = getCurrentPages();
if (pages.length >= 2) {
const prevPage = pages[pages.length - 2] //上一个页面
if (prevPage.onResult) {
prevPage.onResult(data)
}
}
}
// 从当前页面发送数据到目的页面,使用全局变量实现
// 需要用 getTransitData 方法提取
function setTransitData(key, value) {
var g = getApp().globalData
g.transit[key] = value
}
function getTransitData(key) {
var g = getApp().globalData
var v = g.transit[key]
g.transit[key] = null
return v
}
function jwtDecode(token) {
var base64 = token.split('.')[1];
var b = b64.atob(base64)
return JSON.parse(b)
}
// check to see if the user token is expired or
// will expire within the next 30 minutes (1800 seconds).
// If not, there is nothing we really need to do here.
function jwtExpire(token, ahead) {
if (!ahead) {
ahead = 1800
}
if (Date.now()/1000 < jwtDecode(token).exp - ahead) {
return false
}
return true
}
// hashtag
function hashtag(text) {
var regex = /#[^#]+#/g
if (text) {
return text.match(regex)
}
return null
}
// Test white space
// Instead of checking the entire string to see if there's only whitespace,
// just check to see if there's at least one character of non whitespace:
function isWhiteSpace(str) {
return !str || (!/\S/.test(str))
}
// Parse json
function jsonParse(str) {
var r = {}
try {
r.object = JSON.parse(str)
r.ok = true
} catch (e) {
r.ok = false
r.err = e
}
return r
}
// update list item
function getCityName(addr) {
var city = undefined
if (addr) {
console.log("get add:" + addr)
var index0 = addr.indexOf('省')
var index1 = addr.indexOf('市')
if (index0 > 0 && index1 > 0 && index1 > index0 ) {
city = addr.substring(index0+1, index1+1)
} else if (addr.includes('北京市')) {
city = '北京市'
} else if (addr.includes('上海市')) {
city = '上海市'
} else if (addr.includes('天津市')) {
city = '天津市'
} else if (addr.includes('重庆市')) {
city = '重庆市'
}
}
return city
}
function lightenColor(col, amt) {
if (col[0] == "#") {
col = col.slice(1);
}
var num = parseInt(col, 16);
var r = (num >> 16) + amt;
if (r > 255) r = 255;
else if (r < 0) r = 0;
var b = ((num >> 8) & 0x00FF) + amt;
if (b > 255) b = 255;
else if (b < 0) b = 0;
var g = (num & 0x0000FF) + amt;
if (g > 255) g = 255;
else if (g < 0) g = 0;
return "#" + padZero(r.toString(16)) + padZero(b.toString(16)) + padZero(g.toString(16));
}
function alphaColor(col, amt) {
if (col[0] == "#") {
col = col.slice(1);
}
var num = parseInt(col, 16);
var r = (num >> 16);
var g = ((num >> 8) & 0x00FF);
var b = (num & 0x0000FF);
return `rgba(${r}, ${g}, ${b}, ${amt})`
}
function invertColor(hex, bw) {
if (hex.indexOf('#') === 0) {
hex = hex.slice(1);
}
// convert 3-digit hex to 6-digits.
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
if (hex.length !== 6) {
throw new Error('Invalid HEX color.');
}
var r = parseInt(hex.slice(0, 2), 16),
g = parseInt(hex.slice(2, 4), 16),
b = parseInt(hex.slice(4, 6), 16);
if (bw) {
// http://stackoverflow.com/a/3943023/112731
return (r * 0.299 + g * 0.587 + b * 0.114) > 186
? '#000000'
: '#ffffff';
}
// invert color components
r = (255 - r).toString(16);
g = (255 - g).toString(16);
b = (255 - b).toString(16);
// pad each with zeros and return
return "#" + padZero(r) + padZero(g) + padZero(b);
}
function padZero(str, len) {
len = len || 2;
var zeros = new Array(len).join('0');
return (zeros + str).slice(-len);
}
module.exports = {
formatTime: formatTime,
agoTime: agoTime,
msgTime: msgTime,
prettyTime: prettyTime,
prettyTimeYMD: prettyTimeYMD,
getDaysFromNow: getDaysFromNow,
setResult: setResult,
sendRequest: setTransitData,
getRequest: getTransitData,
jwtDecode: jwtDecode,
jwtExpire: jwtExpire,
hashtag: hashtag,
isWhiteSpace: isWhiteSpace,
jsonParse: jsonParse,
getCityName: getCityName,
lightenColor: lightenColor,
invertColor: invertColor,
alphaColor: alphaColor,
}
没有合适的资源?快使用搜索试试~ 我知道了~
云开发校园微社区微信小程序源码/二手交易/兼职交友微信小程序开源源码
共106个文件
png:49个
js:14个
json:13个
2 下载量 85 浏览量
2023-04-20
14:03:28
上传
评论 2
收藏 1.27MB ZIP 举报
温馨提示
云开发校园微社区微信小程序开源源码,这是一款云开发校园微社区-二手交易_兼职_交友_项目微信小程序开源源码,可以给你提供快捷方便的校园生活,有很多有趣实用的板块和功能,如:闲置交易、表白交友、疑问互答、任务兼职、相约学习、失物招领、趣事分享等。 在发布栏目可以发布我们想要发布的上述内容,如上传图片或视频,并且可以选择是否匿名发布和发布位置,可以很好的保护自己的隐私。功能尚未全部完善,感兴趣的朋友可以自行完善并使用。 板块分类:闲置交易、表白交友、疑问互答、失物招领等等 可发布帖子,发布帖子时有包括发布地点、是否匿名、分区板块、可添加文字内容、可添加图片或视频内容 首页轮播图广告 首页轮播公共聊天区最新聊天内容 展示帖子详细信息,可进行评论、分享、点赞、删除等功能 展示个人信息区(用户信息、等级、积分、帖子等等 扩展更多功能(商城、修改个人信息、在线刷题、
资源推荐
资源详情
资源评论
收起资源包目录
云开发校园微社区微信小程序源码/二手交易/兼职交友微信小程序开源源码 (106个子文件)
tieba.jpg 196KB
news.jpg 193KB
从这联系我.jpg 59KB
从这联系我.jpg 59KB
1.jpg 38KB
2.jpg 37KB
3.jpg 25KB
util.js 7KB
article.js 4KB
controller.js 3KB
b64.js 3KB
index.js 3KB
send.js 2KB
article-detail.js 1KB
me.js 998B
message.js 912B
square.js 910B
search.js 878B
app.js 446B
me-info.js 246B
fishei.js 0B
project.config.json 2KB
app.json 1KB
project.private.config.json 410B
sitemap.json 197B
me.json 75B
me-info.json 51B
index.json 33B
message.json 29B
article-detail.json 29B
search.json 29B
send.json 29B
article.json 29B
square.json 29B
zafu.png 265KB
other.png 17KB
arrow_right.png 15KB
anonymous.png 14KB
share.png 14KB
edit_third.png 14KB
love-mood.png 13KB
message_active.png 13KB
send.png 13KB
search.png 13KB
part-time-job.png 12KB
me_active.png 11KB
news.png 11KB
found.png 11KB
communication.png 10KB
square_active.png 10KB
comment.png 10KB
study.png 10KB
message.png 9KB
second-hand.png 8KB
my.png 8KB
unlike.png 8KB
collect.png 8KB
comment-y.png 8KB
like.png 8KB
edit_second.png 8KB
nocollect.png 8KB
me.png 7KB
index.png 7KB
home_active.png 7KB
trade.png 7KB
message.png 7KB
square.png 7KB
back.png 7KB
home.png 7KB
question-ask.png 7KB
my_second.png 7KB
edit.png 7KB
directing.png 6KB
Sign.png 5KB
next.png 3KB
vertical.png 2KB
more.png 2KB
dwon.png 2KB
del.png 1KB
video.png 702B
clear.png 698B
plus.png 690B
photo.png 533B
VIP会员下载整站资源永久免费-98素材网.url 114B
下载说明.url 113B
index.wxml 6KB
me.wxml 5KB
article.wxml 4KB
article-detail.wxml 4KB
send.wxml 3KB
search.wxml 1KB
me-info.wxml 86B
message.wxml 76B
square.wxml 72B
weui.wxss 100KB
weui-icon.wxss 26KB
index.wxss 5KB
article-detail.wxss 4KB
me.wxss 4KB
article.wxss 3KB
共 106 条
- 1
- 2
资源评论
网创学长
- 粉丝: 1770
- 资源: 914
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功