diff --git a/cloudfunctions/callback/config.json b/cloudfunctions/callback/config.json new file mode 100644 index 0000000..43aa5fc --- /dev/null +++ b/cloudfunctions/callback/config.json @@ -0,0 +1,7 @@ +{ + "permissions": { + "openapi": [ + "customerServiceMessage.send" + ] + } +} \ No newline at end of file diff --git a/cloudfunctions/callback/index.js b/cloudfunctions/callback/index.js new file mode 100644 index 0000000..2f4ff45 --- /dev/null +++ b/cloudfunctions/callback/index.js @@ -0,0 +1,25 @@ +const cloud = require('wx-server-sdk') + +cloud.init({ + // API 调用都保持和云函数当前所在环境一致 + env: cloud.DYNAMIC_CURRENT_ENV +}) + +// 云函数入口函数 +exports.main = async (event, context) => { + console.log(event) + + const { OPENID } = cloud.getWXContext() + + const result = await cloud.openapi.customerServiceMessage.send({ + touser: OPENID, + msgtype: 'text', + text: { + content: `收到:${event.Content}`, + } + }) + + console.log(result) + + return result +} diff --git a/cloudfunctions/callback/package.json b/cloudfunctions/callback/package.json new file mode 100644 index 0000000..2e6bc01 --- /dev/null +++ b/cloudfunctions/callback/package.json @@ -0,0 +1,14 @@ +{ + "name": "callback", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "wx-server-sdk": "~2.5.1" + } +} \ No newline at end of file diff --git a/cloudfunctions/echo/config.json b/cloudfunctions/echo/config.json new file mode 100644 index 0000000..16348ce --- /dev/null +++ b/cloudfunctions/echo/config.json @@ -0,0 +1,5 @@ +{ + "permissions": { + "openapi": [] + } +} diff --git a/cloudfunctions/echo/index.js b/cloudfunctions/echo/index.js new file mode 100644 index 0000000..4f83878 --- /dev/null +++ b/cloudfunctions/echo/index.js @@ -0,0 +1,8 @@ +const cloud = require('wx-server-sdk') + +exports.main = async (event, context) => { + // event.userInfo 是已废弃的保留字段,在此不做展示 + // 获取 OPENID 等微信上下文请使用 cloud.getWXContext() + delete event.userInfo + return event +} diff --git a/cloudfunctions/echo/package.json b/cloudfunctions/echo/package.json new file mode 100644 index 0000000..78bff6b --- /dev/null +++ b/cloudfunctions/echo/package.json @@ -0,0 +1,14 @@ +{ + "name": "echo", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "wx-server-sdk": "~2.5.1" + } +} \ No newline at end of file diff --git a/cloudfunctions/getOpenid/config.json b/cloudfunctions/getOpenid/config.json new file mode 100644 index 0000000..5ecc33e --- /dev/null +++ b/cloudfunctions/getOpenid/config.json @@ -0,0 +1,6 @@ +{ + "permissions": { + "openapi": [ + ] + } +} \ No newline at end of file diff --git a/cloudfunctions/getOpenid/index.js b/cloudfunctions/getOpenid/index.js new file mode 100644 index 0000000..ba95da2 --- /dev/null +++ b/cloudfunctions/getOpenid/index.js @@ -0,0 +1,16 @@ +// 云函数入口文件 +const cloud = require('wx-server-sdk') + +cloud.init() + +// 云函数入口函数 +exports.main = async (event, context) => { + const wxContext = cloud.getWXContext() + + return { + event, + openid: wxContext.OPENID, + appid: wxContext.APPID, + unionid: wxContext.UNIONID, + } +} \ No newline at end of file diff --git a/cloudfunctions/getOpenid/package.json b/cloudfunctions/getOpenid/package.json new file mode 100644 index 0000000..547a30a --- /dev/null +++ b/cloudfunctions/getOpenid/package.json @@ -0,0 +1,14 @@ +{ + "name": "getOpenid", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "wx-server-sdk": "~2.5.1" + } +} \ No newline at end of file diff --git a/cloudfunctions/getcollect/config.json b/cloudfunctions/getcollect/config.json new file mode 100644 index 0000000..5ecc33e --- /dev/null +++ b/cloudfunctions/getcollect/config.json @@ -0,0 +1,6 @@ +{ + "permissions": { + "openapi": [ + ] + } +} \ No newline at end of file diff --git a/cloudfunctions/getcollect/index.js b/cloudfunctions/getcollect/index.js new file mode 100644 index 0000000..f3f1b83 --- /dev/null +++ b/cloudfunctions/getcollect/index.js @@ -0,0 +1,25 @@ +// 云函数入口文件 +const cloud = require('wx-server-sdk') + +cloud.init() + +// 云函数入口函数 +exports.main = async (event, context) => { + const wxContext = cloud.getWXContext() + var len_collect=event.collect.length + var len_content=event.content.length + var array=new Array() + first:for(var i=0;i { + const wxContext = cloud.getWXContext() + var len_like=event.like.length + var len_content=event.content.length + var array=new Array() + first:for(var i=0;i { + console.log(event) + console.log(context) + + // 可执行其他自定义逻辑 + // console.log 的内容可以在云开发云函数调用日志查看 + + // 获取 WX Context (微信调用上下文),包括 OPENID、APPID、及 UNIONID(需满足 UNIONID 获取条件)等信息 + const wxContext = cloud.getWXContext() + + return { + event, + openid: wxContext.OPENID, + appid: wxContext.APPID, + unionid: wxContext.UNIONID, + env: wxContext.ENV, + } +} + diff --git a/cloudfunctions/login/package.json b/cloudfunctions/login/package.json new file mode 100644 index 0000000..029ec82 --- /dev/null +++ b/cloudfunctions/login/package.json @@ -0,0 +1,14 @@ +{ + "name": "login", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "wx-server-sdk": "~2.5.1" + } +} diff --git a/cloudfunctions/openapi/config.json b/cloudfunctions/openapi/config.json new file mode 100644 index 0000000..0074569 --- /dev/null +++ b/cloudfunctions/openapi/config.json @@ -0,0 +1,15 @@ +{ + "permissions": { + "openapi": [ + "wxacode.get", + "subscribeMessage.send", + "subscribeMessage.addTemplate", + "templateMessage.send", + "templateMessage.addTemplate", + "templateMessage.deleteTemplate", + "templateMessage.getTemplateList", + "templateMessage.getTemplateLibraryById", + "templateMessage.getTemplateLibraryList" + ] + } +} \ No newline at end of file diff --git a/cloudfunctions/openapi/index.js b/cloudfunctions/openapi/index.js new file mode 100644 index 0000000..be4cfe8 --- /dev/null +++ b/cloudfunctions/openapi/index.js @@ -0,0 +1,86 @@ +// 云函数入口文件 +const cloud = require('wx-server-sdk') + +cloud.init() + +// 云函数入口函数 +exports.main = async (event, context) => { + console.log(event) + switch (event.action) { + case 'requestSubscribeMessage': { + return requestSubscribeMessage(event) + } + case 'sendSubscribeMessage': { + return sendSubscribeMessage(event) + } + case 'getWXACode': { + return getWXACode(event) + } + case 'getOpenData': { + return getOpenData(event) + } + default: { + return + } + } +} + +async function requestSubscribeMessage(event) { + // 此处为模板 ID,开发者需要到小程序管理后台 - 订阅消息 - 公共模板库中添加模板, + // 然后在我的模板中找到对应模板的 ID,填入此处 + return '请到管理后台申请模板 ID 然后在此替换' // 如 'N_J6F05_bjhqd6zh2h1LHJ9TAv9IpkCiAJEpSw0PrmQ' +} + +async function sendSubscribeMessage(event) { + const { OPENID } = cloud.getWXContext() + + const { templateId } = event + + const sendResult = await cloud.openapi.subscribeMessage.send({ + touser: OPENID, + templateId, + miniprogram_state: 'developer', + page: 'pages/openapi/openapi', + // 此处字段应修改为所申请模板所要求的字段 + data: { + thing1: { + value: '咖啡', + }, + time3: { + value: '2020-01-01 00:00', + }, + } + }) + + return sendResult +} + +async function getWXACode(event) { + // 此处将获取永久有效的小程序码,并将其保存在云文件存储中,最后返回云文件 ID 给前端使用 + + const wxacodeResult = await cloud.openapi.wxacode.get({ + path: 'pages/openapi/openapi', + }) + + const fileExtensionMatches = wxacodeResult.contentType.match(/\/([^/]+)/) + const fileExtension = (fileExtensionMatches && fileExtensionMatches[1]) || 'jpg' + + const uploadResult = await cloud.uploadFile({ + // 云文件路径,此处为演示采用一个固定名称 + cloudPath: `wxacode_default_openapi_page.${fileExtension}`, + // 要上传的文件内容可直接传入图片 Buffer + fileContent: wxacodeResult.buffer, + }) + + if (!uploadResult.fileID) { + throw new Error(`upload failed with empty fileID and storage server status code ${uploadResult.statusCode}`) + } + + return uploadResult.fileID +} + +async function getOpenData(event) { + return cloud.getOpenData({ + list: event.openData.list, + }) +} diff --git a/cloudfunctions/openapi/package.json b/cloudfunctions/openapi/package.json new file mode 100644 index 0000000..2760a42 --- /dev/null +++ b/cloudfunctions/openapi/package.json @@ -0,0 +1,14 @@ +{ + "name": "openapi", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "wx-server-sdk": "~2.5.1" + } +} diff --git a/miniprogram/app.js b/miniprogram/app.js new file mode 100644 index 0000000..298aa6d --- /dev/null +++ b/miniprogram/app.js @@ -0,0 +1,36 @@ +//app.js +App({ + onLaunch: function () { + + if (!wx.cloud) { + console.error('请使用 2.2.3 或以上的基础库以使用云能力') + } else { + wx.cloud.init({ + // env 参数说明: + // env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源 + // 此处请填入环境 ID, 环境 ID 可打开云控制台查看 + // 如不填则使用默认环境(第一个创建的环境) + env: 'gzyzx1-3ghhs462720864e0', + traceUser: true, + }) + + this.getOpenId = (function(that){ + return new Promise((resolve, reject) =>{ + wx.cloud.callFunction({ + name: 'getOpenid', + data: {}, + success: res => { + that.globalData.openid = res.result.openid + resolve(res.result.openid) + }, + fail: err => { + console.error('[云函数] [getOpenid] 调用失败', err) + } + }) + }) + })(this) + } + + this.globalData = {} + } +}) diff --git a/miniprogram/app.json b/miniprogram/app.json new file mode 100644 index 0000000..96dff10 --- /dev/null +++ b/miniprogram/app.json @@ -0,0 +1,46 @@ +{ + "pages": [ + "pages/find/find", + "pages/community/community", + "pages/my/my", + "pages/publish/publish", + "pages/detail/detail", + "pages/index/index", + "pages/more/more", + "pages/choose/choose", + "pages/webview/webview" + ], + "window": { + "backgroundColor": "#F6F6F6", + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#F6F6F6", + "navigationBarTitleText": "中医专线", + "navigationBarTextStyle": "black" + }, + "tabBar": { + "color": "#000000", + "selectedColor": "#000000", + "list": [ + { + "pagePath": "pages/find/find", + "text": "发现", + "iconPath": "images/fx.png", + "selectedIconPath": "images/fx_selected.png" + }, + { + "pagePath": "pages/community/community", + "text": "社区", + "iconPath": "images/sq.png", + "selectedIconPath": "images/sq_selected.png" + }, + { + "pagePath": "pages/my/my", + "text": "我的", + "iconPath": "images/wd.png", + "selectedIconPath": "images/wd_selected.png" + } + ] + }, + "sitemapLocation": "sitemap.json", + "style": "v2" +} \ No newline at end of file diff --git a/miniprogram/app.wxss b/miniprogram/app.wxss new file mode 100644 index 0000000..2683af8 --- /dev/null +++ b/miniprogram/app.wxss @@ -0,0 +1,183 @@ +/**app.wxss**/ +/* miniprogram/pages/community/community.wxss */ +button { + background: initial; +} +button:focus{ + outline: 0; +} +button::after{ + border: none; +} +page { + background: #f6f6f6; + display: flex; + flex-direction: column; + justify-content: flex-start; +} + +.userinfo, .uploader, .tunnel { + margin-top: 40rpx; + height: 140rpx; + width: 100%; + background: #fff; + border: 1px solid rgba(0, 0, 0, 0.1); + border-left: none; + border-right: none; + display: flex; + flex-direction: row; + align-items: center; + transition: all 300ms ease; +} +.userinfo-avatar { + width: 100rpx; + height: 100rpx; + margin: 20rpx; + border-radius: 50%; + background-size: cover; + background-color: white; +} +.userinfo-avatar:after { + border: none; +} +.userinfo-nickname { + font-size: 32rpx; + color: #007aff; + background-color: white; + background-size: cover; +} +.userinfo-nickname::after { + border: none; +} +.uploader, .tunnel { + height: auto; + padding: 0 0 0 40rpx; + flex-direction: column; + align-items: flex-start; + box-sizing: border-box; +} +.uploader-text, .tunnel-text { + width: 100%; + line-height: 52px; + font-size: 34rpx; + color: #007aff; +} +.uploader-container { + width: 100%; + height: 400rpx; + padding: 20rpx 20rpx 20rpx 0; + display: flex; + align-content: center; + justify-content: center; + box-sizing: border-box; + border-top: 1px solid rgba(0, 0, 0, 0.1); +} +.uploader-image { + width: 100%; + height: 360rpx; +} +.tunnel { + padding: 0 0 0 40rpx; +} +.tunnel-text { + position: relative; + color: #222; + display: flex; + flex-direction: row; + align-content: center; + justify-content: space-between; + box-sizing: border-box; + border-top: 1px solid rgba(0, 0, 0, 0.1); +} +.tunnel-text:first-child { + border-top: none; +} +.tunnel-switch { + position: absolute; + right: 20rpx; + top: -2rpx; +} +.disable { + color: #888; +} +.service { + position: fixed; + right: 40rpx; + bottom: 40rpx; + width: 140rpx; + height: 140rpx; + border-radius: 50%; + background: linear-gradient(#007aff, #0063ce); + box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3); + display: flex; + align-content: center; + justify-content: center; + transition: all 300ms ease; +} +.service-button { + position: absolute; + top: 40rpx; +} +.service:active { + box-shadow: none; +} +.request-text { + padding: 20rpx 0; + font-size: 24rpx; + line-height: 36rpx; + word-break: break-all; +} +.clear::after{ + content: ""; + display: block; + clear: both; +} +.container2{ + width: 670rpx; + margin: 0 40rpx; +} +.c-bottom{ + margin: 10rpx auto; + text-align: center; + font-size: 20rpx; + color: #8c8c8c; + margin-bottom: 100rpx; +} +.search{ + width: 100%; + height: 60rpx; + margin: 30rpx 0; + background-color: #ccc; + border-radius: 25rpx; +} +.search2{ + width: 610rpx; + height: 60rpx; + margin: 0 30rpx; + display: flex; +} +.search-input{ + width: 500rpx; + height: 60rpx; +} +.search-input input{ + width: 100%; + height: 60rpx; + text-align: left; +} +.search-submit{ + width: 100rpx; + height: 60rpx; + margin-left: 10rpx; +} +.search-submit image{ + width: 50rpx; + height: 50rpx; + margin: 5rpx 25rpx; +} +.container { + display: flex; + flex-direction: column; + box-sizing: border-box; + background-color: #fff; +} \ No newline at end of file diff --git a/miniprogram/components/chatroom/chatroom.js b/miniprogram/components/chatroom/chatroom.js new file mode 100644 index 0000000..adeec16 --- /dev/null +++ b/miniprogram/components/chatroom/chatroom.js @@ -0,0 +1,337 @@ +const FATAL_REBUILD_TOLERANCE = 10 +const SETDATA_SCROLL_TO_BOTTOM = { + scrollTop: 100000, + scrollWithAnimation: true, +} + +Component({ + properties: { + envId: String, + collection: String, + groupId: String, + groupName: String, + userInfo: Object, + onGetUserInfo: { + type: Function, + }, + getOpenID: { + type: Function, + }, + }, + + data: { + chats: [], + textInputValue: '', + openId: '', + scrollTop: 0, + scrollToMessage: '', + hasKeyboard: false, + }, + + methods: { + onGetUserInfo(e) { + this.properties.onGetUserInfo(e) + }, + + getOpenID() { + return this.properties.getOpenID() + }, + + mergeCommonCriteria(criteria) { + return { + groupId: this.data.groupId, + ...criteria, + } + }, + + async initRoom() { + this.try(async () => { + await this.initOpenID() + + const { envId, collection } = this.properties + this.db = wx.cloud.database({ + env: envId, + }) + const db = this.db + const _ = db.command + + const { data: initList } = await db.collection(collection).where(this.mergeCommonCriteria()).orderBy('sendTimeTS', 'desc').get() + + console.log('init query chats', initList) + + this.setData({ + chats: initList.reverse(), + scrollTop: 10000, + }) + + this.initWatch(initList.length ? { + sendTimeTS: _.gt(initList[initList.length - 1].sendTimeTS), + } : {}) + }, '初始化失败') + }, + + async initOpenID() { + return this.try(async () => { + const openId = await this.getOpenID() + + this.setData({ + openId, + }) + }, '初始化 openId 失败') + }, + + async initWatch(criteria) { + this.try(() => { + const { collection } = this.properties + const db = this.db + const _ = db.command + + console.warn(`开始监听`, criteria) + this.messageListener = db.collection(collection).where(this.mergeCommonCriteria(criteria)).watch({ + onChange: this.onRealtimeMessageSnapshot.bind(this), + onError: e => { + if (!this.inited || this.fatalRebuildCount >= FATAL_REBUILD_TOLERANCE) { + this.showError(this.inited ? '监听错误,已断开' : '初始化监听失败', e, '重连', () => { + this.initWatch(this.data.chats.length ? { + sendTimeTS: _.gt(this.data.chats[this.data.chats.length - 1].sendTimeTS), + } : {}) + }) + } else { + this.initWatch(this.data.chats.length ? { + sendTimeTS: _.gt(this.data.chats[this.data.chats.length - 1].sendTimeTS), + } : {}) + } + }, + }) + }, '初始化监听失败') + }, + + onRealtimeMessageSnapshot(snapshot) { + console.warn(`收到消息`, snapshot) + + if (snapshot.type === 'init') { + this.setData({ + chats: [ + ...this.data.chats, + ...[...snapshot.docs].sort((x, y) => x.sendTimeTS - y.sendTimeTS), + ], + }) + this.scrollToBottom() + this.inited = true + } else { + let hasNewMessage = false + let hasOthersMessage = false + const chats = [...this.data.chats] + for (const docChange of snapshot.docChanges) { + switch (docChange.queueType) { + case 'enqueue': { + hasOthersMessage = docChange.doc._openid !== this.data.openId + const ind = chats.findIndex(chat => chat._id === docChange.doc._id) + if (ind > -1) { + if (chats[ind].msgType === 'image' && chats[ind].tempFilePath) { + chats.splice(ind, 1, { + ...docChange.doc, + tempFilePath: chats[ind].tempFilePath, + }) + } else chats.splice(ind, 1, docChange.doc) + } else { + hasNewMessage = true + chats.push(docChange.doc) + } + break + } + } + } + this.setData({ + chats: chats.sort((x, y) => x.sendTimeTS - y.sendTimeTS), + }) + if (hasOthersMessage || hasNewMessage) { + this.scrollToBottom() + } + } + }, + + async onConfirmSendText(e) { + this.try(async () => { + if (!e.detail.value) { + return + } + + const { collection } = this.properties + const db = this.db + const _ = db.command + + const doc = { + _id: `${Math.random()}_${Date.now()}`, + groupId: this.data.groupId, + avatar: this.data.userInfo.avatarUrl, + nickName: this.data.userInfo.nickName, + msgType: 'text', + textContent: e.detail.value, + sendTime: new Date(), + sendTimeTS: Date.now(), // fallback + } + + this.setData({ + textInputValue: '', + chats: [ + ...this.data.chats, + { + ...doc, + _openid: this.data.openId, + writeStatus: 'pending', + }, + ], + }) + this.scrollToBottom(true) + + await db.collection(collection).add({ + data: doc, + }) + + this.setData({ + chats: this.data.chats.map(chat => { + if (chat._id === doc._id) { + return { + ...chat, + writeStatus: 'written', + } + } else return chat + }), + }) + }, '发送文字失败') + }, + + async onChooseImage(e) { + wx.chooseImage({ + count: 1, + sourceType: ['album', 'camera'], + success: async res => { + const { envId, collection } = this.properties + const doc = { + _id: `${Math.random()}_${Date.now()}`, + groupId: this.data.groupId, + avatar: this.data.userInfo.avatarUrl, + nickName: this.data.userInfo.nickName, + msgType: 'image', + sendTime: new Date(), + sendTimeTS: Date.now(), // fallback + } + + this.setData({ + chats: [ + ...this.data.chats, + { + ...doc, + _openid: this.data.openId, + tempFilePath: res.tempFilePaths[0], + writeStatus: 0, + }, + ] + }) + this.scrollToBottom(true) + + const uploadTask = wx.cloud.uploadFile({ + cloudPath: `${this.data.openId}/${Math.random()}_${Date.now()}.${res.tempFilePaths[0].match(/\.(\w+)$/)[1]}`, + filePath: res.tempFilePaths[0], + config: { + env: envId, + }, + success: res => { + this.try(async () => { + await this.db.collection(collection).add({ + data: { + ...doc, + imgFileID: res.fileID, + }, + }) + }, '发送图片失败') + }, + fail: e => { + this.showError('发送图片失败', e) + }, + }) + + uploadTask.onProgressUpdate(({ progress }) => { + this.setData({ + chats: this.data.chats.map(chat => { + if (chat._id === doc._id) { + return { + ...chat, + writeStatus: progress, + } + } else return chat + }) + }) + }) + }, + }) + }, + + onMessageImageTap(e) { + wx.previewImage({ + urls: [e.target.dataset.fileid], + }) + }, + + scrollToBottom(force) { + if (force) { + console.log('force scroll to bottom') + this.setData(SETDATA_SCROLL_TO_BOTTOM) + return + } + + this.createSelectorQuery().select('.body').boundingClientRect(bodyRect => { + this.createSelectorQuery().select(`.body`).scrollOffset(scroll => { + if (scroll.scrollTop + bodyRect.height * 3 > scroll.scrollHeight) { + console.log('should scroll to bottom') + this.setData(SETDATA_SCROLL_TO_BOTTOM) + } + }).exec() + }).exec() + }, + + async onScrollToUpper() { + if (this.db && this.data.chats.length) { + const { collection } = this.properties + const _ = this.db.command + const { data } = await this.db.collection(collection).where(this.mergeCommonCriteria({ + sendTimeTS: _.lt(this.data.chats[0].sendTimeTS), + })).orderBy('sendTimeTS', 'desc').get() + this.data.chats.unshift(...data.reverse()) + this.setData({ + chats: this.data.chats, + scrollToMessage: `item-${data.length}`, + scrollWithAnimation: false, + }) + } + }, + + async try(fn, title) { + try { + await fn() + } catch (e) { + this.showError(title, e) + } + }, + + showError(title, content, confirmText, confirmCallback) { + console.error(title, content) + wx.showModal({ + title, + content: content.toString(), + showCancel: confirmText ? true : false, + confirmText, + success: res => { + res.confirm && confirmCallback() + }, + }) + }, + }, + + ready() { + global.chatroom = this + this.initRoom() + this.fatalRebuildCount = 0 + }, +}) diff --git a/miniprogram/components/chatroom/chatroom.json b/miniprogram/components/chatroom/chatroom.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/miniprogram/components/chatroom/chatroom.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/components/chatroom/chatroom.wxml b/miniprogram/components/chatroom/chatroom.wxml new file mode 100644 index 0000000..056a44c --- /dev/null +++ b/miniprogram/components/chatroom/chatroom.wxml @@ -0,0 +1,85 @@ + + + + + + {{groupName}} + + + + + + + + + + {{item.nickName}} + + + {{item.writeStatus}}% + + + + + + ··· + {{item.textContent}} + + + + + + + + + + + + + + + + + + + + + diff --git a/miniprogram/components/chatroom/chatroom.wxss b/miniprogram/components/chatroom/chatroom.wxss new file mode 100644 index 0000000..d726127 --- /dev/null +++ b/miniprogram/components/chatroom/chatroom.wxss @@ -0,0 +1,161 @@ +.chatroom { + width: 100%; + height: 100%; + display: flex; + flex-direction: column; +} + +.chatroom .header { + flex-basis: fit-content; + display: flex; + flex-direction: row; + border-bottom: 1px solid #ddd; + padding: 20rpx 0 30rpx; + font-size: 30rpx; + /* background: rgb(34, 187, 47); + color: rgba(255, 255, 255, 1) */ + /* font-family: 'Microsoft YaHei' */ +} + +.chatroom .header .left { + flex: 1; +} + +.chatroom .header .middle { + flex: 2; + text-align: center; +} + +.chatroom .header .right { + flex: 1; +} + +.chatroom .body { + flex: 2; + display: flex; + flex-direction: column; + background: rgb(237,237,237); + padding-bottom: 16rpx; +} + +.body .message { + display: flex; + flex-direction: row; + position: relative; + margin: 12rpx 0; +} + +.body .message.message__self { + flex-direction: row-reverse; +} + +.body .message .avatar { + position: relative; + top: 5rpx; + width: 60rpx; + height: 60rpx; + border-radius: 5rpx; + margin: 15rpx; +} + +.body .message .main { + flex: 1; + display: flex; + flex-direction: column; + align-items: flex-start; +} + +.body .message.message__self .main { + align-items: flex-end; +} + +.body .message .nickname { + font-size: 24rpx; + color: #444; +} + +.body .message .text-content { + border: 1px solid transparent; + border-radius: 3px; + background-color: #fff; + margin: 2px 0 0 0; + padding: 4px 10px; + font-size: 30rpx; + display: inline-block; +} + +.body .message.message__self .text-content { + background-color: paleturquoise; +} + +.body .message .text-wrapper { + display: flex; + flex-direction: row; + align-items: center; + max-width: 80%; +} + +.body .message.message__self .text-wrapper .loading{ + font-size: 16rpx; + margin-right: 18rpx; +} + +.body .message .image-wrapper { + display: flex; + flex-direction: row; + align-items: center; +} + +.body .message .image-content { + max-width: 240rpx; + max-height: 240rpx; +} + +.body .message.message__self .image-wrapper .loading { + font-size: 20rpx; + margin-right: 18rpx; +} + +.chatroom .footer { + flex-basis: fit-content; + display: flex; + flex-direction: row; + border-top: 1px solid #ddd; + font-size: 10rpx; + padding: 20rpx 30rpx; + background: rgb(246,246,246); +} + +.chatroom .footer .message-sender { + flex: 1; + display: flex; + flex-direction: row; +} + +.message-sender .text-input { + flex: 1; + font-size: 16px; + border: 1px solid transparent; + border-radius: 5px; + padding: 3px 6px; + margin: 0 10px 0 5px; + background: #fff; +} + +.message-sender .btn-send-image { + width: 50rpx; + height: 50rpx; + align-self: center; +} + +button { + font-size: 30rpx; +} + +button.userinfo { + background: darkturquoise; + color: aliceblue; + padding: 0 100rpx; + border: 1px solid #ddd; + border-radius: 20px; +} diff --git a/miniprogram/components/chatroom/dots.gif b/miniprogram/components/chatroom/dots.gif new file mode 100644 index 0000000..17582e4 Binary files /dev/null and b/miniprogram/components/chatroom/dots.gif differ diff --git a/miniprogram/components/chatroom/photo.png b/miniprogram/components/chatroom/photo.png new file mode 100644 index 0000000..ddc4f34 Binary files /dev/null and b/miniprogram/components/chatroom/photo.png differ diff --git a/miniprogram/images/1.png b/miniprogram/images/1.png new file mode 100644 index 0000000..a2a594c Binary files /dev/null and b/miniprogram/images/1.png differ diff --git a/miniprogram/images/2.png b/miniprogram/images/2.png new file mode 100644 index 0000000..e9c75d6 Binary files /dev/null and b/miniprogram/images/2.png differ diff --git a/miniprogram/images/3.png b/miniprogram/images/3.png new file mode 100644 index 0000000..64bd72c Binary files /dev/null and b/miniprogram/images/3.png differ diff --git a/miniprogram/images/4.png b/miniprogram/images/4.png new file mode 100644 index 0000000..149c630 Binary files /dev/null and b/miniprogram/images/4.png differ diff --git a/miniprogram/images/5.png b/miniprogram/images/5.png new file mode 100644 index 0000000..4ed17c3 Binary files /dev/null and b/miniprogram/images/5.png differ diff --git a/miniprogram/images/6.png b/miniprogram/images/6.png new file mode 100644 index 0000000..d724f3d Binary files /dev/null and b/miniprogram/images/6.png differ diff --git a/miniprogram/images/ch-med.png b/miniprogram/images/ch-med.png new file mode 100644 index 0000000..729d190 Binary files /dev/null and b/miniprogram/images/ch-med.png differ diff --git a/miniprogram/images/college.png b/miniprogram/images/college.png new file mode 100644 index 0000000..0c3246b Binary files /dev/null and b/miniprogram/images/college.png differ diff --git a/miniprogram/images/comment.png b/miniprogram/images/comment.png new file mode 100644 index 0000000..ed6a42e Binary files /dev/null and b/miniprogram/images/comment.png differ diff --git a/miniprogram/images/default.png b/miniprogram/images/default.png new file mode 100644 index 0000000..2e1cf30 Binary files /dev/null and b/miniprogram/images/default.png differ diff --git a/miniprogram/images/dt.png b/miniprogram/images/dt.png new file mode 100644 index 0000000..80c30e1 Binary files /dev/null and b/miniprogram/images/dt.png differ diff --git a/miniprogram/images/f.png b/miniprogram/images/f.png new file mode 100644 index 0000000..3457e7d Binary files /dev/null and b/miniprogram/images/f.png differ diff --git a/miniprogram/images/favor-active.png b/miniprogram/images/favor-active.png new file mode 100644 index 0000000..5fae333 Binary files /dev/null and b/miniprogram/images/favor-active.png differ diff --git a/miniprogram/images/favor.png b/miniprogram/images/favor.png new file mode 100644 index 0000000..5a71882 Binary files /dev/null and b/miniprogram/images/favor.png differ diff --git a/miniprogram/images/fx.png b/miniprogram/images/fx.png new file mode 100644 index 0000000..0a9f951 Binary files /dev/null and b/miniprogram/images/fx.png differ diff --git a/miniprogram/images/fx_selected.png b/miniprogram/images/fx_selected.png new file mode 100644 index 0000000..2a5a594 Binary files /dev/null and b/miniprogram/images/fx_selected.png differ diff --git a/miniprogram/images/good-active.png b/miniprogram/images/good-active.png new file mode 100644 index 0000000..57a9461 Binary files /dev/null and b/miniprogram/images/good-active.png differ diff --git a/miniprogram/images/good.png b/miniprogram/images/good.png new file mode 100644 index 0000000..1c096cf Binary files /dev/null and b/miniprogram/images/good.png differ diff --git a/miniprogram/images/hwqklgxds.png b/miniprogram/images/hwqklgxds.png new file mode 100644 index 0000000..9e81544 Binary files /dev/null and b/miniprogram/images/hwqklgxds.png differ diff --git a/miniprogram/images/jnjs.png b/miniprogram/images/jnjs.png new file mode 100644 index 0000000..ce67771 Binary files /dev/null and b/miniprogram/images/jnjs.png differ diff --git a/miniprogram/images/more.png b/miniprogram/images/more.png new file mode 100644 index 0000000..2582fe4 Binary files /dev/null and b/miniprogram/images/more.png differ diff --git a/miniprogram/images/no.png b/miniprogram/images/no.png new file mode 100644 index 0000000..9154af5 Binary files /dev/null and b/miniprogram/images/no.png differ diff --git a/miniprogram/images/note.png b/miniprogram/images/note.png new file mode 100644 index 0000000..d04f0ac Binary files /dev/null and b/miniprogram/images/note.png differ diff --git a/miniprogram/images/partjob.png b/miniprogram/images/partjob.png new file mode 100644 index 0000000..729f8c7 Binary files /dev/null and b/miniprogram/images/partjob.png differ diff --git a/miniprogram/images/publish.png b/miniprogram/images/publish.png new file mode 100644 index 0000000..f3261d6 Binary files /dev/null and b/miniprogram/images/publish.png differ diff --git a/miniprogram/images/recycle.png b/miniprogram/images/recycle.png new file mode 100644 index 0000000..f328f55 Binary files /dev/null and b/miniprogram/images/recycle.png differ diff --git a/miniprogram/images/school.png b/miniprogram/images/school.png new file mode 100644 index 0000000..212a9cc Binary files /dev/null and b/miniprogram/images/school.png differ diff --git a/miniprogram/images/smtp.png b/miniprogram/images/smtp.png new file mode 100644 index 0000000..f2723a8 Binary files /dev/null and b/miniprogram/images/smtp.png differ diff --git a/miniprogram/images/sq.png b/miniprogram/images/sq.png new file mode 100644 index 0000000..0f25eaa Binary files /dev/null and b/miniprogram/images/sq.png differ diff --git a/miniprogram/images/sq_selected.png b/miniprogram/images/sq_selected.png new file mode 100644 index 0000000..2bfb067 Binary files /dev/null and b/miniprogram/images/sq_selected.png differ diff --git a/miniprogram/images/ss.png b/miniprogram/images/ss.png new file mode 100644 index 0000000..77d268e Binary files /dev/null and b/miniprogram/images/ss.png differ diff --git a/miniprogram/images/swyy.png b/miniprogram/images/swyy.png new file mode 100644 index 0000000..2e2eb62 Binary files /dev/null and b/miniprogram/images/swyy.png differ diff --git a/miniprogram/images/time.png b/miniprogram/images/time.png new file mode 100644 index 0000000..ca7736b Binary files /dev/null and b/miniprogram/images/time.png differ diff --git a/miniprogram/images/top.png b/miniprogram/images/top.png new file mode 100644 index 0000000..6bcb5df Binary files /dev/null and b/miniprogram/images/top.png differ diff --git a/miniprogram/images/upload.png b/miniprogram/images/upload.png new file mode 100644 index 0000000..c73660c Binary files /dev/null and b/miniprogram/images/upload.png differ diff --git a/miniprogram/images/wd.png b/miniprogram/images/wd.png new file mode 100644 index 0000000..722861b Binary files /dev/null and b/miniprogram/images/wd.png differ diff --git a/miniprogram/images/wd_selected.png b/miniprogram/images/wd_selected.png new file mode 100644 index 0000000..9ae75b7 Binary files /dev/null and b/miniprogram/images/wd_selected.png differ diff --git a/miniprogram/pages/choose/choose.js b/miniprogram/pages/choose/choose.js new file mode 100644 index 0000000..cb4419a --- /dev/null +++ b/miniprogram/pages/choose/choose.js @@ -0,0 +1,82 @@ +// pages/choose/choose.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + recycle:function(){ + wx.navigateTo({ + url: '../publish/publish?mode=recycle', + }) + }, + partjob:function(){ + wx.navigateTo({ + url: '../publish/publish?mode=partjob', + }) + }, + college:function(){ + wx.navigateTo({ + url: '../publish/publish?mode=college', + }) + }, + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + wx.removeStorage({ + key: 'content', + }) + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/miniprogram/pages/choose/choose.json b/miniprogram/pages/choose/choose.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/miniprogram/pages/choose/choose.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/pages/choose/choose.wxml b/miniprogram/pages/choose/choose.wxml new file mode 100644 index 0000000..f260b92 --- /dev/null +++ b/miniprogram/pages/choose/choose.wxml @@ -0,0 +1,21 @@ + + + + + + + 二手闲置 + + + + + + 兼职实习 + + + + + + 校园资讯 + + \ No newline at end of file diff --git a/miniprogram/pages/choose/choose.wxss b/miniprogram/pages/choose/choose.wxss new file mode 100644 index 0000000..6647c62 --- /dev/null +++ b/miniprogram/pages/choose/choose.wxss @@ -0,0 +1,26 @@ +/* pages/choose/choose.wxss */ +.container2>view{ + margin-top: 40rpx; + border-radius: 20rpx; + box-shadow: 5px 5px 5px #888888; + border-bottom: 1px solid #808080; + display: flex; + flex-wrap: wrap; + width: 100%; + height: 200rpx; + align-items: center; + justify-content: space-evenly; + font-size: 40rpx; + font-weight: 700; +} +.img{ + width: 100rpx; + height: 100rpx; +} +.container2>view>view{ + display: inline-block +} +image{ + width: 100%; + height: 100%; +} \ No newline at end of file diff --git a/miniprogram/pages/community/community.js b/miniprogram/pages/community/community.js new file mode 100644 index 0000000..f9da17e --- /dev/null +++ b/miniprogram/pages/community/community.js @@ -0,0 +1,1646 @@ +// miniprogram/pages/community/community.js +var util = require('../../utils/util.js') +const app = getApp(); +const db=wx.cloud.database().collection('user') +const dd=wx.cloud.database() +const db2=wx.cloud.database().collection('community') +Page({ + + /** + * 页面的初始数据 + */ + data: { + currentdate:'', + main_top:'', + choose:'', + ischoose:false, + search:'', + issearch:false, + isend:false, + isrefresh:true, + isrefresh1:true, + commentinput:'', + getprofile:'', + inputcon:'', + openid: '', + id:"", + c_index:"", + array: ['二手闲置', '兼职实习', '校园资讯'], + new_:'active', + hot_:'', + iscomment:false, + good_src:'../../images/good.png', + favor_src:'../../images/favor.png', + userInfo: {}, + hasUserInfo: false, + canIUseGetUserProfile: false, + content:[], + like:[], + like_video:[], + comment:[], + collect:[], + collect_video:[], + mylike:[], + mylike_video:[], + mycollect:[], + mycollect_video:[], + video:[] + }, + getUserProfile(e) { + const that=this + // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认 + // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 + wx.getUserProfile({ + desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true, + + }) + wx.setStorageSync('userInfo', that.data.userInfo) + db.add({ + data:{ + _id:that.data.openid, + nickName:that.data.userInfo.nickName, + avatarUrl:that.data.userInfo.avatarUrl, + city:that.data.userInfo.city, + collect:[], + like:[], + collect_video:[], + like_video:[], + } + }).then(()=>{ + that.setData({ + getprofile:true + }) + }) + } + }) + }, + inputchange:function(e){ + this.setData({ + inputcon: e.detail.value + }) + }, + search:function(){ + var that = this; + if(this.data.inputcon==''){ + wx.showToast({ + title: '请输入搜索内容!', + icon:'none' + }) + }else{ + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + that.backtop() + var key = this.data.inputcon; + if(that.data.new_==''){ + dd.collection('video').orderBy("date","desc").where({ + type: dd.RegExp({ + regexp: key, + options: 'i' + }) + }).get({ + success: function(res) { + console.log(res.data) + that.setData({ + inputcon: '', + }) + if(res.data.length==0){ + wx.showToast({ + title: '搜索内容暂无!', + icon:'none' + }) + }else{ + that.setData({ + video:res.data, + issearch:true, + search:key + }) + that.getlike_video(that.data.mylike_video,res.data) + that.getcollect_video(that.data.mycollect_video,res.data) + } + wx.hideLoading() + } + }) + }else{ + dd.collection('community').orderBy("date","desc").where({ + type: dd.RegExp({ + regexp: key, + options: 'i' + }) + }) + .get({ + success: function(res) { + console.log(res.data) + that.setData({ + inputcon: '' + }) + if(res.data.length==0){ + wx.showToast({ + title: '搜索内容暂无!', + icon:'none' + }) + }else{ + that.setData({ + content:res.data, + issearch:true, + search:key, + like:[], + collect:[] + }) + wx.setStorage({ + data: res.data, + key: 'content', + }) + that.getlike(that.data.mylike,res.data) + that.getcollect(that.data.mycollect,res.data) + } + + } + }) + } + + } + }, + formSubmit(e) { + const that= this + var input_content=e.detail.value.com_content + var _time = util.formatTime(new Date()) + if(!input_content){ + wx.showToast({ + title: '请输入评论内容!', + icon:'none' + }) + return + } + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + const _=dd.command + if(that.data.new_==''){ + dd.collection('comment_video').add({ + data: { + commentid: that.data.id, + username:that.data.userInfo.nickName, + img:that.data.userInfo.avatarUrl, + content:input_content, + date:_time + }, + success: function(res) { + // res 是一个对象,其中有 _id 字段标记刚创建的记录的 id + /* wx.removeStorageSync(that.data.id) + wx.removeStorageSync('content') */ + + that.close(); + console.log(that.data.video[that.data.c_index].comment) + const a = `video[${that.data.c_index}].comment` + var c=that.data.video[that.data.c_index].comment + that.setData({ + [a]:++c, + commentinput:'' + }) + dd.collection('video').doc(that.data.id).update({ + data:{ + comment:c + } + }).then(()=>{ + + wx.hideLoading() + wx.showToast({ + title: '评论成功!', + }) + }) + } + }) + }else{ + dd.collection('comment').add({ + data: { + commentid: that.data.id, + username:that.data.userInfo.nickName, + img:that.data.userInfo.avatarUrl, + content:input_content, + date:_time + }, + success: function(res) { + // res 是一个对象,其中有 _id 字段标记刚创建的记录的 id + /* wx.removeStorageSync(that.data.id) + wx.removeStorageSync('content') */ + + that.close(); + console.log(that.data.content[that.data.c_index].comment) + const a = `content[${that.data.c_index}].comment` + var c=that.data.content[that.data.c_index].comment + that.setData({ + [a]:++c, + commentinput:'' + }) + db2.doc(that.data.id).update({ + data:{ + comment:c + } + }).then(()=>{ + wx.setStorageSync('content', that.data.content) + wx.hideLoading() + wx.showToast({ + title: '评论成功!', + }) + }) + } + }) + } + + + }, + good_video:function(e){ + const that=this + if(!that.data.hasUserInfo&&!that.data.getprofile){ + wx.getUserProfile({ + desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + that.setData({ + userInfo: res.userInfo, + hasUserInfo: true, + }) + wx.setStorageSync('userInfo', that.data.userInfo) + db.add({ + data:{ + _id:that.data.openid, + nickName:that.data.userInfo.nickName, + avatarUrl:that.data.userInfo.avatarUrl, + city:that.data.userInfo.city, + collect:[], + collect_video:[], + like_video:[], + like:[] + } + }).then(()=>{ + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + + var index=e.currentTarget.dataset.index + var id=e.currentTarget.dataset.id + const a = `like_video[${index}]` + const b = `video[${index}].like_video` + var c=that.data.video[index].like_video + var d=that.data.mylike_video + const _=dd.command + if(that.data.like_video[index]==1){ + that.setData({ + [a]:0, + [b]:--c + }) + db.doc(that.data.openid).update({ + data:{ + like_video:_.pull(id) + } + }).then(()=>{ + that.setData({ + mylike_video:that.removeval(d,id) + }) + }) + dd.collection('video').doc(id).update({ + data: { + // 表示指示数据库将字段自增 -1 + like_video: _.inc(-1) + }, + success: function(res) { + /* console.log(res.data) */ + wx.setStorageSync('content', that.data.content) + /* wx.removeStorageSync('content') */ + wx.hideLoading() + } + }) + }else{ + that.setData({ + [a]:1, + [b]:++c + }) + db.doc(that.data.openid).update({ + data:{ + like_video:_.push(id) + } + }).then(()=>{ + that.setData({ + mylike_video:d.concat(id) + }) + }) + dd.collection('video').doc(id).update({ + data: { + // 表示指示数据库将字段自增 1 + like_video: _.inc(1) + }, + success: function(res) { + /* console.log(res.data) */ + wx.setStorageSync('content', that.data.content) + wx.hideLoading() + } + }) + } + }) + } + }) + }else{ + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + + var index=e.currentTarget.dataset.index + var id=e.currentTarget.dataset.id + const a = `like_video[${index}]` + const b = `video[${index}].like_video` + var c=that.data.video[index].like_video + var d=that.data.mylike_video + const _=dd.command + if(that.data.like_video[index]==1){ + that.setData({ + [a]:0, + [b]:--c + }) + db.doc(that.data.openid).update({ + data:{ + like_video:_.pull(id) + } + }).then(()=>{ + that.setData({ + mylike_video:that.removeval(d,id) + }) + }) + dd.collection('video').doc(id).update({ + data: { + // 表示指示数据库将字段自增 -1 + like_video: _.inc(-1) + }, + success: function(res) { + /* console.log(res.data) */ + /* wx.removeStorageSync('content') */ + wx.hideLoading() + } + }) + }else{ + that.setData({ + [a]:1, + [b]:++c + }) + db.doc(that.data.openid).update({ + data:{ + like_video:_.push(id) + } + }).then(()=>{ + that.setData({ + mylike_video:d.concat(id) + }) + }) + dd.collection('video').doc(id).update({ + data: { + // 表示指示数据库将字段自增 1 + like_video: _.inc(1) + }, + success: function(res) { + /* console.log(res.data) */ + wx.hideLoading() + } + }) + } + } + }, + good:function(e){ + const that=this + if(!that.data.hasUserInfo&&!that.data.getprofile){ + wx.getUserProfile({ + desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + that.setData({ + userInfo: res.userInfo, + hasUserInfo: true, + }) + wx.setStorageSync('userInfo', that.data.userInfo) + db.add({ + data:{ + _id:that.data.openid, + nickName:that.data.userInfo.nickName, + avatarUrl:that.data.userInfo.avatarUrl, + city:that.data.userInfo.city, + collect:[], + like:[], + collect_video:[], + like_video:[], + } + }).then(()=>{ + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + + var index=e.currentTarget.dataset.index + var id=e.currentTarget.dataset.id + const a = `like[${index}]` + const b = `content[${index}].like` + var c=that.data.content[index].like + var d=that.data.mylike + const _=dd.command + if(that.data.like[index]==1){ + that.setData({ + [a]:0, + [b]:--c + }) + db.doc(that.data.openid).update({ + data:{ + like:_.pull(id) + } + }).then(()=>{ + that.setData({ + mylike:that.removeval(d,id) + }) + }) + db2.doc(id).update({ + data: { + // 表示指示数据库将字段自增 -1 + like: _.inc(-1) + }, + success: function(res) { + /* console.log(res.data) */ + wx.setStorageSync('content', that.data.content) + /* wx.removeStorageSync('content') */ + wx.hideLoading() + } + }) + }else{ + that.setData({ + [a]:1, + [b]:++c + }) + db.doc(that.data.openid).update({ + data:{ + like:_.push(id) + } + }).then(()=>{ + that.setData({ + mylike:d.concat(id) + }) + }) + db2.doc(id).update({ + data: { + // 表示指示数据库将字段自增 1 + like: _.inc(1) + }, + success: function(res) { + /* console.log(res.data) */ + wx.setStorageSync('content', that.data.content) + wx.hideLoading() + } + }) + } + }) + } + }) + }else{ + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + + var index=e.currentTarget.dataset.index + var id=e.currentTarget.dataset.id + const a = `like[${index}]` + const b = `content[${index}].like` + var c=that.data.content[index].like + var d=that.data.mylike + const _=dd.command + if(that.data.like[index]==1){ + that.setData({ + [a]:0, + [b]:--c + }) + db.doc(that.data.openid).update({ + data:{ + like:_.pull(id) + } + }).then(()=>{ + that.setData({ + mylike:that.removeval(d,id) + }) + }) + db2.doc(id).update({ + data: { + // 表示指示数据库将字段自增 -1 + like: _.inc(-1) + }, + success: function(res) { + /* console.log(res.data) */ + wx.setStorageSync('content', that.data.content) + /* wx.removeStorageSync('content') */ + wx.hideLoading() + } + }) + }else{ + that.setData({ + [a]:1, + [b]:++c + }) + db.doc(that.data.openid).update({ + data:{ + like:_.push(id) + } + }).then(()=>{ + that.setData({ + mylike:d.concat(id) + }) + }) + db2.doc(id).update({ + data: { + // 表示指示数据库将字段自增 1 + like: _.inc(1) + }, + success: function(res) { + /* console.log(res.data) */ + wx.setStorageSync('content', that.data.content) + wx.hideLoading() + } + }) + } + } + + }, + removeval:function(array,val){ + for (var i = 0; i < array.length; i++) { + if (array[i] == val) { + array.splice(i, 1); + } + } + return array + }, + favor_video:function(e){ + const that=this + if(!that.data.hasUserInfo&&!that.data.getprofile){ + wx.getUserProfile({ + desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + that.setData({ + userInfo: res.userInfo, + hasUserInfo: true, + }) + wx.setStorageSync('userInfo', that.data.userInfo) + db.add({ + data:{ + _id:that.data.openid, + nickName:that.data.userInfo.nickName, + avatarUrl:that.data.userInfo.avatarUrl, + city:that.data.userInfo.city, + collect:[], + collect_video:[], + like_video:[], + like:[] + } + }).then(()=>{ + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + + var index=e.currentTarget.dataset.index + var id=e.currentTarget.dataset.id + const a = `collect_video[${index}]` + const b = `video[${index}].collect_video` + var c=that.data.video[index].collect_video + var d=that.data.mycollect_video + const _=dd.command + if(that.data.collect_video[index]==1){ + that.setData({ + [a]:0, + [b]:--c + }) + db.doc(that.data.openid).update({ + data:{ + collect_video:_.pull(id) + } + }).then(()=>{ + that.setData({ + mycollect_video:that.removeval(d,id) + }) + }) + dd.collection('video').doc(id).update({ + data: { + // 表示指示数据库将字段自增 -1 + collect_video: _.inc(-1) + }, + success: function(res) { + /* console.log(res.data) */ + wx.setStorageSync('content', that.data.content) + /* wx.removeStorageSync('content') */ + wx.hideLoading() + } + }) + }else{ + that.setData({ + [a]:1, + [b]:++c + }) + db.doc(that.data.openid).update({ + data:{ + collect_video:_.push(id) + } + }).then(()=>{ + that.setData({ + mycollect_video:d.concat(id) + }) + }) + dd.collection('video').doc(id).update({ + data: { + // 表示指示数据库将字段自增 1 + collect_video: _.inc(1) + }, + success: function(res) { + /* console.log(res.data) */ + wx.setStorageSync('content', that.data.content) + wx.hideLoading() + } + }) + } + }) + } + }) + }else{ + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + + var index=e.currentTarget.dataset.index + var id=e.currentTarget.dataset.id + const a = `collect_video[${index}]` + const b = `video[${index}].collect_video` + var c=that.data.video[index].collect_video + var d=that.data.mycollect_video + const _=dd.command + if(that.data.collect_video[index]==1){ + that.setData({ + [a]:0, + [b]:--c + }) + db.doc(that.data.openid).update({ + data:{ + collect_video:_.pull(id) + } + }).then(()=>{ + that.setData({ + mycollect_video:that.removeval(d,id) + }) + }) + dd.collection('video').doc(id).update({ + data: { + // 表示指示数据库将字段自增 -1 + collect_video: _.inc(-1) + }, + success: function(res) { + /* console.log(res.data) */ + /* wx.removeStorageSync('content') */ + wx.hideLoading() + } + }) + }else{ + that.setData({ + [a]:1, + [b]:++c + }) + db.doc(that.data.openid).update({ + data:{ + collect_video:_.push(id) + } + }).then(()=>{ + that.setData({ + mycollect_video:d.concat(id) + }) + }) + console.log(id) + dd.collection('video').doc(id).update({ + data: { + // 表示指示数据库将字段自增 1 + collect_video: _.inc(1) + }, + success: function(res) { + /* console.log(res.data) */ + wx.hideLoading() + } + }) + } + } + }, + favor:function(e){ + const that=this + if(!that.data.hasUserInfo&&!that.data.getprofile){ + wx.getUserProfile({ + desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + that.setData({ + userInfo: res.userInfo, + hasUserInfo: true, + }) + wx.setStorageSync('userInfo', that.data.userInfo) + db.add({ + data:{ + _id:that.data.openid, + nickName:that.data.userInfo.nickName, + avatarUrl:that.data.userInfo.avatarUrl, + city:that.data.userInfo.city, + collect:[], + like:[], + collect_video:[], + like_video:[], + } + }).then(()=>{ + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + + var id=e.currentTarget.dataset.id + var index=e.currentTarget.dataset.index + const a = `collect[${index}]` + const b = `content[${index}].collect_num` + var c=that.data.content[index].collect_num + var d=that.data.mycollect + const _=dd.command + if(that.data.collect[index]==1){ + that.setData({ + [a]:0, + [b]:--c + }) + db.doc(that.data.openid).update({ + data:{ + collect:_.pull(id) + } + }).then(()=>{ + that.setData({ + mycollect:that.removeval(d,id) + }) + }) + db2.doc(id).update({ + data: { + // 表示指示数据库将字段自增 -1 + collect_num: _.inc(-1) + }, + success: function(res) { + wx.setStorageSync('content', that.data.content) + wx.hideLoading() + } + }) + }else{ + that.setData({ + [a]:1, + [b]:++c + }) + db.doc(that.data.openid).update({ + data:{ + collect:_.push(id) + } + }).then(()=>{ + that.setData({ + mycollect:d.concat(id) + }) + }) + db2.doc(id).update({ + data: { + collect_num: _.inc(1) + }, + success: function(res) { + wx.setStorageSync('content', that.data.content) + wx.hideLoading() + } + }) + } + }) + } + }) + }else{ + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + + var id=e.currentTarget.dataset.id + var index=e.currentTarget.dataset.index + const a = `collect[${index}]` + const b = `content[${index}].collect_num` + var c=that.data.content[index].collect_num + var d=that.data.mycollect + const _=dd.command + if(that.data.collect[index]==1){ + that.setData({ + [a]:0, + [b]:--c + }) + db.doc(that.data.openid).update({ + data:{ + collect:_.pull(id) + } + }).then(()=>{ + that.setData({ + mycollect:that.removeval(d,id) + }) + }) + db2.doc(id).update({ + data: { + // 表示指示数据库将字段自增 -1 + collect_num: _.inc(-1) + }, + success: function(res) { + wx.setStorageSync('content', that.data.content) + wx.hideLoading() + } + }) + }else{ + that.setData({ + [a]:1, + [b]:++c + }) + db.doc(that.data.openid).update({ + data:{ + collect:_.push(id) + } + }).then(()=>{ + that.setData({ + mycollect:d.concat(id) + }) + }) + db2.doc(id).update({ + data: { + collect_num: _.inc(1) + }, + success: function(res) { + wx.setStorageSync('content', that.data.content) + wx.hideLoading() + } + }) + } + } + + }, + comment:function(e){ + const that=this + + that.setData({ + comment:[] + }) + var index=e.currentTarget.dataset.index + if(that.data.new_==''){ + dd.collection('comment_video').orderBy("date","desc").where({ + commentid:that.data.video[index]._id + }).get({ + success: function(res) { + // res.data 是包含以上定义的两条记录的数组 + wx.showLoading({ + title: '加载中', + mask:'true' + }) + that.setData({ + comment:res.data, + id:that.data.video[index]._id, + c_index:index + }, () => { + wx.hideLoading() + }) + } + }) + }else{ + dd.collection('comment').orderBy("date","desc").where({ + commentid:that.data.content[index]._id + }).get({ + success: function(res) { + // res.data 是包含以上定义的两条记录的数组 + wx.showLoading({ + title: '加载中', + mask:'true' + }) + that.setData({ + comment:res.data, + id:that.data.content[index]._id, + c_index:index + }, () => { + wx.hideLoading() + }) + } + }) + } + + that.setData({ + iscomment:true, + }) + }, + close:function(){ + const that=this + that.setData({ + iscomment:false, + }) + }, + menu_new:function(){ + const that=this + that.setData({ + new_:'active', + hot_:'' + }) + }, + menu_hot:function(){ + const that=this + var _time = util.formatTime(new Date()) + + that.setData({ + new_:'', + hot_:'active', + like_video:[], + collect_video:[], + currentdate:_time + }) + wx.showLoading({ + title: '加载中...', + mask:'true' + }) +/* var array=wx.getStorageSync('video') + if(array){ + that.setData({ + video:array + }) + wx.hideLoading() + return + } */ + dd.collection('video').get({ + success: function(res) { + console.log(res.data) + that.setData({ + video:res.data + }) + if(that.data.mylike_video!=''){ + that.getlike_video(that.data.mylike_video,res.data) + } + if(that.data.mycollect_video!=''){ + that.getcollect_video(that.data.mycollect_video,res.data) + } + if(that.data.mylike_video==''&&that.data.mycollect_video==''){ + wx.hideLoading() + } + + } + }) + }, + menu_choose:function(){ + const that=this + }, + publish:function(){ + const that=this + if(that.data.hasUserInfo||that.data.getprofile){ + wx.navigateTo({ + url: '../choose/choose', + }) + }else{ + wx.getUserProfile({ + desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + that.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + wx.setStorageSync('userInfo', that.data.userInfo) + + wx.navigateTo({ + url: '../choose/choose', + }) + db.add({ + data:{ + _id:that.data.openid, + nickName:that.data.userInfo.nickName, + avatarUrl:that.data.userInfo.avatarUrl, + city:that.data.userInfo.city, + collect:[], + like:[], + collect_video:[], + like_video:[], + } + }).then() + } + }) + } + + }, + detail:function(e){ + console.log(e.currentTarget.dataset.index) + var index=e.currentTarget.dataset.index + const that=this + console.log(that.data.content[index]) + wx.navigateTo({ + url: '../detail/detail?content='+JSON.stringify(that.data.content[index]), + }) + }, + getlike:function(like,content){ + const that=this + if(that.data.like==''){ + wx.cloud.callFunction({ + // 云函数名称 + name: 'getlike', + // 传给云函数的参数 + data: { + like: like, + content: content, + }, + success: function(res) { + console.log(res.result.array) + that.setData({ + like:res.result.array + }) + if(that.data.like!=''&&that.data.collect!='') + wx.hideLoading() + }, + fail: console.error + }) + }else{ + let old_like=that.data.like + wx.cloud.callFunction({ + // 云函数名称 + name: 'getlike', + // 传给云函数的参数 + data: { + like: like, + content: content, + }, + success: function(res) { + console.log(res.result.array) + that.setData({ + like:old_like.concat(res.result.array) + }) + wx.hideLoading() + }, + fail: console.error + }) + } + + + }, + getcollect:function(collect,content){ + const that=this + if(that.data.collect==''){ + wx.cloud.callFunction({ + // 云函数名称 + name: 'getcollect', + // 传给云函数的参数 + data: { + collect: collect, + content: content, + }, + success: function(res) { + console.log(res.result.array) + that.setData({ + collect:res.result.array + }) + if(that.data.like!=''&&that.data.collect!='') + wx.hideLoading() + }, + fail: console.error + }) + }else{ + let old_collect=that.data.collect + wx.cloud.callFunction({ + // 云函数名称 + name: 'getcollect', + // 传给云函数的参数 + data: { + collect: collect, + content: content, + }, + success: function(res) { + console.log(res.result.array) + that.setData({ + collect:old_collect.concat(res.result.array) + }) + wx.hideLoading() + }, + fail: console.error + }) + } + + }, + getlike_video:function(like,content){ + const that=this + if(that.data.like_video==''){ + wx.cloud.callFunction({ + // 云函数名称 + name: 'getlike', + // 传给云函数的参数 + data: { + like: like, + content: content, + }, + success: function(res) { + console.log(res.result.array) + that.setData({ + like_video:res.result.array + }) + wx.hideLoading() + }, + fail: console.error + }) + }else{ + let old_like=that.data.like_video + wx.cloud.callFunction({ + // 云函数名称 + name: 'getlike', + // 传给云函数的参数 + data: { + like: like, + content: content, + }, + success: function(res) { + console.log(res.result.array) + that.setData({ + like_video:old_like.concat(res.result.array) + }) + wx.hideLoading() + }, + fail: console.error + }) + } + + + }, + getcollect_video:function(collect,content){ + const that=this + if(that.data.collect_video==''){ + wx.cloud.callFunction({ + // 云函数名称 + name: 'getcollect', + // 传给云函数的参数 + data: { + collect: collect, + content: content, + }, + success: function(res) { + console.log(res.result.array) + that.setData({ + collect_video:res.result.array + }) + wx.hideLoading() + }, + fail: console.error + }) + }else{ + let old_collect=that.data.collect_video + wx.cloud.callFunction({ + // 云函数名称 + name: 'getcollect', + // 传给云函数的参数 + data: { + collect: collect, + content: content, + }, + success: function(res) { + console.log(res.result.array) + that.setData({ + collect_video:old_collect.concat(res.result.array) + }) + wx.hideLoading() + }, + fail: console.error + }) + } + + }, + onLoad: function (options) { + const that=this + wx.clearStorage() + app.getOpenId.then(res => { + that.setData({ + openid:res + }) + wx.setStorage({ + data: res, + key: 'openid', + }) + db.doc(res).get({ + success: function(res) { + if(res.data){ + that.setData({ + getprofile:true, + userInfo:{ + nickName:res.data.nickName, + avatarUrl:res.data.avatarUrl + }, + mylike:res.data.like, + mycollect:res.data.collect, + mylike_video:res.data.like_video, + mycollect_video:res.data.collect_video + },()=>{ + wx.setStorage({ + data: that.data.userInfo, + key: 'userInfo', + }) + that.getlike(res.data.like,that.data.content) + that.getcollect(res.data.collect,that.data.content) + }) + } + }, + }) + }) + if (wx.getUserProfile) { + this.setData({ + canIUseGetUserProfile: true + }) + } + }, + bindPickerChange:function(e){ + const that=this + that.backtop() + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + if(that.data.new_==''){ + dd.collection('video').where({ + type:that.data.array[e.detail.value] + }).get({ + success: function(res) { + console.log(res.data) + that.setData({ + video:res.data, + choose:e.detail.value, + ischoose:true, + issearch:false, + + }) + that.getlike_video(that.data.mylike_video,res.data) + that.getcollect_video(that.data.mycollect_video,res.data) + wx.hideLoading() + } + }) + }else{ + db2.orderBy("date","desc").where({ + type:that.data.array[e.detail.value] + }).get({ + success: function(res) { + console.log(res) + that.setData({ + choose:e.detail.value, + content:res.data, + ischoose:true, + issearch:false, + like:[], + collect:[] + }) + wx.setStorage({ + data: res.data, + key: 'content', + }) + that.getlike(that.data.mylike,res.data) + that.getcollect(that.data.mycollect,res.data) + + } + }) + } + }, + + onShow: function () { + + const that=this + var _time = util.formatTime(new Date()) + that.setData({ + currentdate:_time + }) + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + var array=wx.getStorageSync('content') + if(array){ + that.setData({ + content:array, + like:[], + collect:[] + },()=>{ + if(that.data.mylike!=''){ + that.getlike(that.data.mylike,that.data.content) + } + if(that.data.mycollect!=''){ + that.getcollect(that.data.mycollect,that.data.content) + } + + if(that.data.mylike==''&&that.data.mycollect==''){ + wx.hideLoading({ + success: (res) => {}, + }) + } + }) + + return + } + db2.orderBy("date","desc").get({ + + success: function(res) { + that.setData({ + content:res.data, + like:[], + collect:[] + },()=>{ + if(that.data.mylike!=''){ + that.getlike(that.data.mylike,that.data.content) + } + if(that.data.mycollect!=''){ + that.getcollect(that.data.mycollect,that.data.content) + } + if(that.data.mylike==''&&that.data.mycollect==''){ + wx.hideLoading({ + success: (res) => {}, + }) + } + }) + wx.setStorage({ + key:'content', + data:res.data + }) + wx.hideLoading({ + success: (res) => {}, + }) + } + }) + }, + refresh:function(){ + /*下拉刷新 */ + wx.removeStorageSync('content') + this.onShow() + this.setData({ + isrefresh:false, + issearch:false, + ischoose:false + }) + console.log(this.data.isrefresh) + + }, + refresh1:function(){ + this.menu_hot() + this.setData({ + isrefresh1:false + }) + }, + lower(e) { + const that=this +/* if(that.data.isend){ + return + } */ + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + console.log(that.data.issearch) + //判断是搜索的还是筛选的 + if(that.data.issearch==true){ + var key = that.data.search; + if(that.data.new_==''){ + var x=that.data.video.length + let old_data = that.data.video + var _=dd.command + dd.collection('video').orderBy("date","desc").where({ + type: dd.RegExp({ + regexp: key, + options: 'i' + }), + date:_.lt(that.data.currentdate) + }).skip(x).get({ + success: function(res) { + if(res.data.length==0){ + wx.hideLoading() + wx.showToast({ + title: '已经到底啦!', + icon:'none' + }) + }else{ + this.setData({ + video: old_data.concat(res.data), + }) + that.getlike_video(that.data.mylike_video,res.data) + that.getcollect_video(that.data.mycollect_video,res.data) + wx.hideLoading() + } + + } + }) + }else{//在论坛页 + var x=that.data.content.length + let old_data = that.data.content + var _=dd.command + dd.collection('community').orderBy("date","desc").where({ + type: dd.RegExp({ + regexp: key, + options: 'i' + }), + date:_.lt(that.data.currentdate) + }).skip(x) + .get({ + success: function(res) { + + if(res.data.length==0){ + wx.hideLoading() + wx.showToast({ + title: '已经到底啦!', + icon:'none' + }) + }else{ + that.setData({ + content: old_data.concat(res.data), + }) + that.getlike(that.data.mylike,res.data) + that.getcollect(that.data.mycollect,res.data) + wx.hideLoading() + } + } + }) + } + }else if(that.data.ischoose==true){ + console.log('我在筛选') + if(that.data.new_==''){ + var x=that.data.video.length + let old_data = that.data.video + var _=dd.command + dd.collection('video').orderBy("date","desc").where({ + type: that.data.choose, + date:_.lt(that.data.currentdate) + }).skip(x).get({ + success: function(res) { + if(res.data.length==0){ + wx.hideLoading() + wx.showToast({ + title: '已经到底啦!', + icon:'none' + }) + }else{ + this.setData({ + video: old_data.concat(res.data), + }) + that.getlike_video(that.data.mylike_video,res.data) + that.getcollect_video(that.data.mycollect_video,res.data) + wx.hideLoading() + } + + } + }) + }else{//在论坛页 + var x=that.data.content.length + let old_data = that.data.content + var _=dd.command + dd.collection('community').orderBy("date","desc").where({ + type: that.data.choose, + date:_.lt(that.data.currentdate) + }).skip(x) + .get({ + success: function(res) { + if(res.data.length==0){ + wx.hideLoading() + wx.showToast({ + title: '已经到底啦!', + icon:'none' + }) + }else{ + that.setData({ + content: old_data.concat(res.data), + }) + that.getlike(that.data.mylike,res.data) + that.getcollect(that.data.mycollect,res.data) + wx.hideLoading() + } + } + }) + } + } + else { + if(that.data.new_==''){ + var x=that.data.video.length + let old_data = that.data.video + var _=dd.command + dd.collection('video').orderBy("date","desc").where({ + + date:_.lt(that.data.currentdate) + }).skip(x).get({ + success: function(res) { + if(res.data.length==0){ + wx.hideLoading() + wx.showToast({ + title: '已经到底啦!', + icon:'none' + }) + }else{ + this.setData({ + video: old_data.concat(res.data), + }) + that.getlike_video(that.data.mylike_video,res.data) + that.getcollect_video(that.data.mycollect_video,res.data) + wx.hideLoading() + } + + } + }) + }else{//在论坛页 + var x=that.data.content.length + let old_data = that.data.content + var _=dd.command + dd.collection('community').orderBy("date","desc").where({ + + date:_.lt(that.data.currentdate) + }).skip(x) + .get({ + success: function(res) { + if(res.data.length==0){ + wx.hideLoading() + wx.showToast({ + title: '已经到底啦!', + icon:'none' + }) + }else{ + that.setData({ + content: old_data.concat(res.data), + }) + that.getlike(that.data.mylike,res.data) + that.getcollect(that.data.mycollect,res.data) + wx.hideLoading() + } + } + }) + } + } + }, + lower2(e){ + const that=this + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + var x=that.data.comment.length + let old_data = that.data.comment + var _=dd.command + if(that.data.new_==''){ + + dd.collection('comment_video').orderBy('date','desc').where({ + commentid:that.data.id, + date:_.lt(that.data.currentdate) + }).skip(x) // 限制返回数量为 20 条 + .get() + .then(res => { + console.log(res.data) + // 利用concat函数连接新数据与旧数据 + if(res.data.length==0){ + wx.hideLoading() + wx.showToast({ + title: '已经到底了!', + icon:'none' + }) + return + } + this.setData({ + comment: old_data.concat(res.data), + }) + console.log(res.data) + wx.hideLoading() + }) + .catch(err => { + console.error(err) + }) + }else{ + dd.collection('comment').orderBy('date','desc').where({ + commentid:that.data.id, + date:_.lt(that.data.currentdate) + }).skip(x) // 限制返回数量为 20 条 + .get() + .then(res => { + console.log(res.data) + // 利用concat函数连接新数据与旧数据 + if(res.data.length==0){ + wx.hideLoading() + wx.showToast({ + title: '已经到底了!', + icon:'none' + }) + return + } + this.setData({ + comment: old_data.concat(res.data), + }) + console.log(res.data) + wx.hideLoading() + }) + .catch(err => { + console.error(err) + }) + } + + + }, + backtop:function(){ + this.setData({ + main_top:0 + }) + } + + +}) \ No newline at end of file diff --git a/miniprogram/pages/community/community.json b/miniprogram/pages/community/community.json new file mode 100644 index 0000000..2fb12a5 --- /dev/null +++ b/miniprogram/pages/community/community.json @@ -0,0 +1,5 @@ +{ + "usingComponents": {}, + "enablePullDownRefresh": true + +} \ No newline at end of file diff --git a/miniprogram/pages/community/community.wxml b/miniprogram/pages/community/community.wxml new file mode 100644 index 0000000..4678b42 --- /dev/null +++ b/miniprogram/pages/community/community.wxml @@ -0,0 +1,181 @@ + + + var transtime=function(dateTime){ + var dateTimeStamp =getDate(dateTime); + var result = ''; + var minute = 1000 * 60; + var hour = minute * 60; + var day = hour * 24; + var halfamonth = day * 15; + var month = day * 30; + var year = day * 365; + var now = getDate(); + var diffValue = now - dateTimeStamp; + if (diffValue < 0) { + return; + } + var monthEnd = diffValue / month; + var weekEnd = diffValue / (7 * day); + var dayEnd = diffValue / day; + var hourEnd = diffValue / hour; + var minEnd = diffValue / minute; + var yearEnd = diffValue / year; + if (yearEnd >= 1) { + result = dateTime; + } else if (monthEnd >= 1) { + result = dateTime; + } else if (dayEnd >= 4) { + result = dateTime; + } else if ((dayEnd >= 1)&&(dayEnd<=3)){ + result = "" + parseInt(dayEnd) + "天前"; + } else if (hourEnd >= 1) { + result = "" + parseInt(hourEnd) + "小时前"; + } else if (minEnd >= 1) { + result = "" + parseInt(minEnd) + "分钟前"; + } else { + result = "刚刚"; + } + return result; + } + module.exports.transtime = transtime + + + + + + + + + + 论坛 + 视频 + + + 筛选 + + + + 回到顶部 + + + + + + + {{index<9?'0'+(index+1):index+1}} + + + #{{item.type}} + + + + #{{item.z_type}}\n + + {{item.recycle.obj_name+'*'+item.recycle.obj_num+':'+item.recycle.obj_price}}\n + + + {{item.partjob.unit+'-'+item.partjob.name}}\n + + {{item.college}}\n + {{func.transtime(item.date)}} + + + + + + + + {{item.like}} + + + + {{item.comment}} + + + + {{item.collect_num}} + + + + 欢迎关注微信公众号:广中E专线一 + + + + + + + + {{index<9?'0'+(index+1):index+1}} + + #{{item.type}}\n + + + + + {{item.like_video}} + + + + {{item.comment}} + + + + {{item.collect_video}} + + + + 欢迎关注微信公众号:广中E专线一 + + + + + + + + + 全部评论 + + + + + + + + + {{item.username}} + \n + {{item.content}} + \n + {{func.transtime(item.date)}} + + + + {{comment==''?'还没有人评论过,快来抢沙发吧~':'欢迎关注微信公众号:中医专线'}} + + +
+ + + + + + + +
+
+ + + diff --git a/miniprogram/pages/community/community.wxss b/miniprogram/pages/community/community.wxss new file mode 100644 index 0000000..07f3217 --- /dev/null +++ b/miniprogram/pages/community/community.wxss @@ -0,0 +1,265 @@ +page{ + height: 100%; + overflow: hidden; +} +.menu{ + width: fit-content; + border-radius: 10rpx; + overflow: hidden; + margin: 0 auto; + text-align: center; +} +.backtop{ +position: relative; +margin-left: 30rpx; +} +.backtop::after{ + position: absolute; + right: 116rpx; + top: 16rpx; + border: 15rpx solid transparent; + border-top: 20rpx solid #808080; + content: ""; + transform: rotate(180deg); +} +.active{ + background-color: #169BD5; + color:#fff!important +} +.menu view{ + display: inline-block; + width:120rpx; + height: 80rpx; + line-height: 80rpx; + font-size: 25rpx; + color: #8C8C8C; +} + +.content:nth-of-type(1) .num{ + background-color: #ca5639!important; +} +.content:nth-of-type(2) .num{ + background-color: #f1c020!important; +} +.content:nth-of-type(3) .num{ + background-color:#ceba04!important; +} +/* .content:nth-last-of-type(1){ + margin-bottom: 500rpx!important; +} */ +.content{ + padding: 10rpx 0; + border-bottom: 1px solid #ddd; +} +.num{ + width:fit-content; + padding: 0 10rpx; + height: 50rpx; + line-height: 50rpx; + border-radius: 10rpx; + background-color: #ddd; + text-align: center; + font-size: 25rpx; + font-weight: 700; +} +.content2{ + width: 100%; + max-width: 500rpx; + height: 160rpx; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + margin-top: 10rpx; + display: inline-block; + clear: both; +} +.title{ + font-size: 30rpx; + color: #169BD5; +} +.title_img{ + width: 35rpx; + height:35rpx; + margin: 0 10rpx; +} +.message{ + font-size: 25rpx; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; + text-overflow: ellipsis; +} +.img{ + width: 150rpx; + height: 150rpx; + float: right; + margin-right: 20rpx; +} +.img image{ + width: 100%; + height: 100%; +} +.con-bottom{ + display: flex; +} +.con-bottom>view{ + display: inline-block; + width: 33%; + height: 50rpx; + line-height: 50rpx; + font-size: 25rpx; + color: #8C8C8C; + +} +.con-bottom image{ + margin-right: 10rpx; + width: 30%; + height: 60%; +} +.good{ + padding-right: 100rpx; + text-align: left; +} +.comment{ + padding: 0 50rpx; + text-align: center; +} +.favor{ + padding-left: 100rpx; + text-align: right; +} +.good>text, +.comment>text, +.favor>text{ + display: inline-block; + width: 50rpx; + text-align: center; +} +.publish{ + padding: 0; + position: absolute; + display: inline-block; + width: 100rpx!important; + height: 100rpx!important; + left: 0; + right: 0; + margin: auto; + bottom: 30rpx; +} +.publish image{ + width: 100%; + height: 100%; +} +video{ + margin: 20rpx 0; + width: 100%; +} +.none{ + bottom: -100%; +} +.show{ + bottom: 0; +} +.container3{ + width: 100%; + height: 100%; + position: absolute; + background-color: transparent; + + transition: 0.5s; +} +.comment1{ + border: 1px solid #ddd; + border-top-left-radius: 20rpx; + border-top-right-radius: 20rpx; + position: absolute; + bottom: 0; + left: 0; + right: 0; + height: 60%; + background-color: #fff; + padding: 20rpx; + overflow: scroll; +} + +.h-cut{ + width: 80rpx; + height: 80rpx; + overflow:hidden; + border-radius: 50%; +} +.h-cut image{ + width: 100%; + height: 100%; +} +.c-title{ + font-weight: 700; +} +.c-content{ + margin-top: 20rpx; + padding: 20rpx 0; + width: 100%; + border-bottom: 1px solid #ddd; + background-color: rgb(255, 255, 255,0.5); +} +.c-content view{ + display: inline-block; +} +.c-content1{ + max-width: 120rpx; + max-height: 160rpx; + text-align: center; + float: left; + margin:5rpx 18rpx; +} +.c-content2{ + max-width: 550rpx; +} +.c-name{ + + font-size: 25rpx; + font-weight: 700; +} +.c-mess{ + font-size: 25rpx; + word-break: break-all; +} +.c-time{ + font-size: 18rpx; + color: #8c8c8c; +} + +.input{ + display: flex; + justify-content: space-around; + align-items: center; + bottom: 0; + position: absolute; + height: 100rpx; + width: 100%; + background-color: #fff; +} +.input1{ + width: 500rpx; + height: 70rpx; + line-height: 70rpx; + border-radius: 20rpx; + border: 1px solid #ddd; +} +.input2{ + padding: 0; + margin: 0!important; + width: 130rpx!important; + height: 70rpx!important; + line-height: 70rpx; + text-align: center; + border-radius: 20rpx; + color: #fff; + background-color: #169BD5; +} + +.v-num,.v-title{ + display: inline-block; + margin-right: 20rpx; +} \ No newline at end of file diff --git a/miniprogram/pages/detail/detail.js b/miniprogram/pages/detail/detail.js new file mode 100644 index 0000000..c0873b6 --- /dev/null +++ b/miniprogram/pages/detail/detail.js @@ -0,0 +1,218 @@ +// miniprogram/pages/detail/detail.js +var util = require('../../utils/util.js') +const app = getApp(); +const db=wx.cloud.database().collection('user') +const dd=wx.cloud.database() +const db2=wx.cloud.database().collection('community') +Page({ + + /** + * 页面的初始数据 + */ + data: { + main_top:'', + openid:'', + currentdate:'', + canIUse: wx.canIUse('button.open-type.getUserInfo'), + userInfo: {}, + hasUserInfo: false, + canIUseGetUserProfile: false, + imgList: [], + head_cut:'', + authorname:'', + content:[], + comment:[], + commentinput:'', + showtop:false + }, + + formSubmit(e) { + const that= this + var input_content=e.detail.value.com_content + var _time = util.formatTime(new Date()) + if(!input_content){ + wx.showToast({ + title: '请输入评论内容!', + icon:'none' + }) + return + } + const _=dd.command + dd.collection('comment').add({ + data: { + commentid: that.data.content._id, + username:that.data.userInfo.nickName, + img:that.data.userInfo.avatarUrl, + content:input_content, + date:_time + }, + success: function(res) { + // res 是一个对象,其中有 _id 字段标记刚创建的记录的 id + console.log(res) + wx.showToast({ + title: '评论成功!', + }) + var array=[{ + commentid: that.data.content._id, + username:that.data.userInfo.nickName, + img:that.data.userInfo.avatarUrl, + content:input_content, + date:_time + }] + that.setData({ + comment:array.concat(that.data.comment), + commentinput:'' + }) + db2.doc(that.data.content._id).update({ + data:{ + comment:_.inc(1) + } + }).then() + } + }) + + }, + preview(event) { + + let currentUrl = event.currentTarget.dataset.src + const that=this + wx.cloud.getTempFileURL({ + fileList:[currentUrl], + success(res){ + console.log(res) + const a = `imgList[${0}]` + that.setData({ + [a]:res.fileList[0].tempFileURL + }) + console.log(that.data.imgList) + wx.previewImage({ + current: currentUrl, // 当前显示图片的http链接 + urls: that.data.imgList // 需要预览的图片http链接列表 + }) + } + }) + + }, + getUserProfile(e) { + // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认 + // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 + const that= this + if(that.data.hasUserInfo){ + console.log(that.data.userInfo) + }else{ + wx.getUserProfile({ + desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + that.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + wx.setStorageSync('userInfo', that.data.userInfo) + db.add({ + data:{ + _id:that.data.openid, + nickName:that.data.userInfo.nickName, + avatarUrl:that.data.userInfo.avatarUrl, + city:that.data.userInfo.city, + collect:[], + like:[] + } + }) + } + }) + } + + }, + onShow:function(){ + const that=this + var _time = util.formatTime(new Date()) + that.setData({ + currentdate:_time + }) + }, + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + const that= this + if (wx.getUserProfile) { + this.setData({ + canIUseGetUserProfile: true + }) + } + var openid=wx.getStorageSync('openid') + that.setData({ + content:JSON.parse(options.content), + comment:[], + openid:openid + }) + db.doc(that.data.content._openid).get({ + success:function(res){ + console.log(res.data) + that.setData({ + head_cut:res.data.avatarUrl, + authorname:res.data.nickName + }) + } + }) + dd.collection('comment').orderBy("date","desc").where({ + commentid:that.data.content._id + }).get({ + success: function(res) { + // res.data 是包含以上定义的两条记录的数组 + wx.showLoading({ + title: '加载中', + mask:'true' + }) + that.setData({ + comment:res.data, + }, () => { + wx.hideLoading() + }) + } + }) + + var arr=wx.getStorageSync('userInfo') + console.log(arr) + that.setData({ + userInfo:arr + }) + + }, + lower(e){ + const that=this + var x=that.data.comment.length + let old_data = that.data.comment + wx.showLoading({ + title: '加载中...', + mask:'true' + }) + var _=dd.command + dd.collection('comment').where({ + commentid:that.data.content._id, + date:_.lt(that.data.currentdate) + }).orderBy('date','desc').skip(x) // 限制返回数量为 20 条 + .get() + .then(res => { + console.log(res.data) + // 利用concat函数连接新数据与旧数据 + if(res.data.length==0){ + wx.hideLoading() + wx.showToast({ + title: '已经到底了!', + icon:'none' + }) + return + } + this.setData({ + comment: old_data.concat(res.data), + }) + wx.hideLoading({ + success: (res) => {}, + }) + }) + .catch(err => { + console.error(err) + }) + } +}) \ No newline at end of file diff --git a/miniprogram/pages/detail/detail.json b/miniprogram/pages/detail/detail.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/miniprogram/pages/detail/detail.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/pages/detail/detail.wxml b/miniprogram/pages/detail/detail.wxml new file mode 100644 index 0000000..61c8cc5 --- /dev/null +++ b/miniprogram/pages/detail/detail.wxml @@ -0,0 +1,79 @@ + + + + + + + + + {{authorname}} + {{content.date}} + + + + #{{content.type}} + + + + #{{content.z_type}}\n + + + 物品名称: {{content.recycle.obj_name}} + 数量(个):{{content.recycle.obj_num}} + 价格(¥):{{content.recycle.obj_price}} + 交易地点:{{content.recycle.obj_address}} + 联系方式:{{content.recycle.obj_contact}} + 备注:\n{{content.recycle.obj_note}} + + + 工作单位:{{content.partjob.unit}} + 岗位名称:{{content.partjob.name}} + 工作时间:{{content.partjob.time}} + 工作地点:{{content.partjob.address}} + 工作内容:\n {{content.partjob.content}} + 工作要求:\n {{content.partjob.require}} + 薪资及发放方式:{{content.partjob.salary}} + 报名方式:{{content.partjob.sign_way}} + 备注:\n {{content.partjob.note}} + + + {{content.college}} + + + + + + + + 全部评论 + + + + + + + + {{item.username}} + \n + + {{item.content}} + + \n + {{item.date}} + + + {{comment==''?'还没有人评论过,快来抢沙发吧~':'欢迎关注微信公众号:广中医专线一'}} + + +
+ + + + + + + +
\ No newline at end of file diff --git a/miniprogram/pages/detail/detail.wxss b/miniprogram/pages/detail/detail.wxss new file mode 100644 index 0000000..da724a4 --- /dev/null +++ b/miniprogram/pages/detail/detail.wxss @@ -0,0 +1,139 @@ +/* miniprogram/pages/detail/detail.wxss */ +.title_img{ + width: 50rpx; + height:50rpx; + margin: -10rpx 10rpx; +} +.author{ + height: 80rpx; + line-height: 40rpx; +} +.author>view{ + display: inline-block; +} +.a-head{ + + width: 80rpx; + height: 80rpx; + overflow: hidden; + border-radius: 50%; +} +.a-head image{ + width: 100%; + height: 100%; +} +.a-content{ + max-width: 80%; + margin-left: 30rpx; +} +.a-name{ + font-weight: 600; +} +.container4{ + padding: 20rpx 40rpx; + background-color: #fff; + /* background-color: aqua; */ +} +.title{ + display: inline-block; + margin-top: 20rpx; + color: #169BD5; + font-size: 40rpx; +} +.content{ + margin: 20rpx 0; + font-size: 30rpx; +} +.content view{ + word-break: break-all; + font-family: fangsong; + line-height: 60rpx; +} +.content view text:nth-of-type(1){ + font-weight: 700; +} +.split{ + margin-top: 20rpx; + border: 2px dashed #8c8c8c; +} +.comment1{ + background-color: #fff; + padding: 20rpx; + margin-bottom: 100rpx; +} +.h-cut{ + width: 80rpx; + height: 80rpx; + overflow:hidden; + border-radius: 50%; +} +.h-cut image{ + width: 100%; + height: 100%; +} +.c-title{ + font-weight: 700; +} +.c-content{ + margin-top: 20rpx; + padding: 20rpx 0; + width: 100%; + border-bottom: 1px solid #ddd; + background-color: rgb(255, 255, 255,0.5); +} +.c-content view{ + display: inline-block; +} +.c-content1{ + max-width: 120rpx; + max-height: 160rpx; + text-align: center; + float: left; + margin:5rpx 18rpx; + +} +.c-content2{ + max-width: 550rpx; +} +.c-name{ + + font-size: 25rpx; + font-weight: 700; +} +.c-mess{ + font-size: 25rpx; + word-break: break-all; +} +.c-time{ + font-size: 15rpx; + color: #8c8c8c; +} + +.input{ + display: flex; + justify-content: space-around; + align-items: center; + bottom: 0; + position: fixed; + height: 100rpx; + width: 100%; + background-color: #fff; +} +.input1{ + width: 500rpx; + height: 70rpx; + line-height: 70rpx; + border-radius: 20rpx; + border: 1px solid #ddd; +} +.input2{ + padding: 0; + margin: 0!important; + width: 130rpx!important; + height: 70rpx!important; + line-height: 70rpx; + text-align: center; + border-radius: 20rpx; + color: #fff; + background-color: #169BD5; +} \ No newline at end of file diff --git a/miniprogram/pages/find/find.js b/miniprogram/pages/find/find.js new file mode 100644 index 0000000..e480ee5 --- /dev/null +++ b/miniprogram/pages/find/find.js @@ -0,0 +1,111 @@ +// miniprogram/pages/find/find.js +const db = wx.cloud.database(); +Page({ + data: { + inputcon:'', + swiperImg: + [],//轮播图图片列表 + showindex1:0, + bannerImg1:[ + 'cloud://iii-apple-5g4fz3cz1a2cc511.6969-iii-apple-5g4fz3cz1a2cc511-1304058842/互联网.png', + 'cloud://iii-apple-5g4fz3cz1a2cc511.6969-iii-apple-5g4fz3cz1a2cc511-1304058842/数学建模.png', + 'cloud://iii-apple-5g4fz3cz1a2cc511.6969-iii-apple-5g4fz3cz1a2cc511-1304058842/数学能力挑战赛.png'], + showindex2:0, + }, + + /** + * 生命周期函数--监听页面加载 + */ + sliderto:function(e){ + console.log(e) + var url=e.currentTarget.dataset.url + wx.navigateTo({ + url: '/pages/webview/webview?url=' + url, + }) + }, + onLoad: function (options) { + const that=this + /*轮播图 */ + db.collection('slider').orderBy('index','asc').get({ + success:function(res){ + that.setData({ + swiperImg:res.data + }) + } + }) + + + /*推荐栏*/ + db.collection('recommend').limit(6).orderBy('index','asc').get({ + success:function(res){ + console.log(res) + that.setData({ + bannerImg1:res.data + }) + } + }) + }, + search: function(){ + var that = this; + if(this.data.inputcon==''){ + wx.showToast({ + title: '请输入搜索内容', + icon:'none' + }) + }else{ + var key = this.data.inputcon; + db.collection('recommend').where({ + title: db.RegExp({ + regexp: key, + options: 'i' + }) + }) + .get({ + success: function(res) { + console.log(res.data) + that.setData({ + inputcon: '' + }) + if(res.data.length==0){ + wx.showToast({ + title: '搜索内容暂无!', + icon:'none' + }) + }else{ + var model = JSON.stringify(res.data); + wx.navigateTo({ + url: '../more/more?model='+model, + }) + } + } + }) + } + }, + bindchange1(e) { + this.setData({ + showindex1: e.detail.current, + }) + }, + bindchange2(e) { + this.setData({ + showindex2: e.detail.current + }) + }, + gotomore1:function(){ + wx.navigateTo({ + url: '../more/more?isfirst=true', + }) + }, + gotomore2:function(){ + wx.navigateTo({ + url: '../more/more?isfirst=false', + }) + }, + gotocompete:function(){ + }, + inputchange:function(e){ + this.setData({ + inputcon: e.detail.value + }) + }, +}) \ No newline at end of file diff --git a/miniprogram/pages/find/find.json b/miniprogram/pages/find/find.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/miniprogram/pages/find/find.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/pages/find/find.wxml b/miniprogram/pages/find/find.wxml new file mode 100644 index 0000000..0fc17e1 --- /dev/null +++ b/miniprogram/pages/find/find.wxml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + 中医内容 + + + 查看更多 + + + + + + + + + + + + + {{item.title}} + + + {{item.note}} + + + + + + + + + + + + + + + 校园生活 + + + 查看更多 + + + + + + + + + + + + + {{item.title}} + + + {{item.note}} + + + + + + + + + + \ No newline at end of file diff --git a/miniprogram/pages/find/find.wxss b/miniprogram/pages/find/find.wxss new file mode 100644 index 0000000..5edf0a6 --- /dev/null +++ b/miniprogram/pages/find/find.wxss @@ -0,0 +1,208 @@ +/* miniprogram/pages/find/find.wxss */ +.container2{ + width: 670rpx; + /* height: 700px; */ + margin: 0 40rpx; + /* background-color: aqua; */ +} +.search{ + width: 100%; + height: 60rpx; + margin: 30rpx 0; + background-color: #ccc; + border-radius: 25rpx; +} +.search2{ + width: 610rpx; + height: 60rpx; + margin: 0 30rpx; + display: flex; +} +.search-input{ + width: 500rpx; + height: 60rpx; +} +.search-input input{ + width: 100%; + height: 60rpx; + text-align: center; +} +.search-submit{ + width: 100rpx; + height: 60rpx; + margin-left: 10rpx; +} +.search-submit image{ + width: 50rpx; + height: 50rpx; + margin: 5rpx 25rpx; +} +.top{ + width: 100%; + margin: 30rpx 0; + height: 350rpx; +} +.top swiper{ + width: 100%; + height: 100%; + border-radius: 25rpx; + overflow: hidden; +} +.top swiper swiper-item{ + width: 100%; + height: 100%; + border-radius: 25rpx; +} +.top swiper swiper-item image{ + width: 100%; + height: 100%; + border-radius: 25rpx; +} +.main{ + width: 100%; + min-height: 400rpx; + overflow: hidden; +} +.main-top{ + width: 100%; + height: 60rpx; + display: flex; + margin: 10rpx 0; +} +.main-top-left, .main-top-right{ + flex: 1; + height: 60rpx; +} +.main-top-left-img{ + float: left; + width: 60rpx; + height: 60rpx; +} +.main-top-left-img image{ + width: 100%; + height: 100%; +} +.main-top-left-text{ + float: left; + width: 200rpx; + margin-left: 10rpx; + height: 60rpx; + line-height: 60rpx; + font-weight: 700; +} +.main-top-right{ + display: flex; +} +.main-top-right-text{ + /* float: right; */ + width: 270rpx; + text-align: right; + color: gold; + height: 60rpx; + line-height: 60rpx; + +} +.main-top-right-img{ + /* float: right; */ + width: 40rpx; + height: 40rpx; + margin: 10rpx; +} +.main-top-right-img image{ + width: 100%; + height: 100%; +} +.main-center{ + width: 100%; +} + +.slide{ + width: 100%; + height: 320rpx; +} + +.slide>.picker{ + width: 100%; + height: 320rpx; +} +.slide>.picker .picker-one{ + width:100%; + height: 320rpx; + position: relative; +} +.slide>.picker .picker-one .imgs{ + width: 450rpx; + height: 200rpx; + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + margin: 30rpx auto; + border-radius: 20rpx; + transform: scale(1); + animation: change 0.5s linear +} + + @keyframes change{ + 0%{transform: scale(0.8)} + 100%{transform: scale(1);} +} + +.slide>.picker .picker-one .imgs1{ + width: 500rpx; + height: 200rpx; + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + margin: 30rpx auto; + border-radius: 20rpx; + transform: scale(0.8); + animation: change1 0.5s linear +} + +@keyframes change1{ + 0%{transform: scale(1)} + 100%{transform: scale(0.8);} +} +.picker-two{ + text-align: center; + width: 100%; + position: absolute; + bottom: 0; + /* left: 50rpx; */ +} +.picker-two-title{ + margin: 5rpx 0; + width: 100%; + height: 30rpx; + line-height: 30rpx; + font-size: 25rpx; + font-weight: 700; +} +.picker-two-con{ + display: flex; + width: 100%; + height: 30rpx; + margin: 5rpx 0; + line-height: 30rpx; + font-size: 25rpx; + justify-content: center; +} +.picker-two-icon{ + width: 25rpx; + height: 25rpx; + margin-right: 8rpx; +} +.picker-two-icon image{ + width: 100%; + height: 100%; +} +.picker-two-time{ + overflow: hidden; + text-overflow: ellipsis; + max-width: 280rpx; +} + \ No newline at end of file diff --git a/miniprogram/pages/index/index.js b/miniprogram/pages/index/index.js new file mode 100644 index 0000000..d17408f --- /dev/null +++ b/miniprogram/pages/index/index.js @@ -0,0 +1,124 @@ +//index.js +const app = getApp() + +Page({ + data: { + avatarUrl: './user-unlogin.png', + userInfo: {}, + hasUserInfo: false, + logged: false, + takeSession: false, + requestResult: '', + canIUseGetUserProfile: false, + canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') // 如需尝试获取用户信息可改为false + }, + + onLoad: function() { + if (!wx.cloud) { + wx.redirectTo({ + url: '../chooseLib/chooseLib', + }) + return + } + if (wx.getUserProfile) { + this.setData({ + canIUseGetUserProfile: true, + }) + } + }, + + getUserProfile() { + // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 + wx.getUserProfile({ + desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + this.setData({ + avatarUrl: res.userInfo.avatarUrl, + userInfo: res.userInfo, + hasUserInfo: true, + }) + } + }) + }, + + onGetUserInfo: function(e) { + if (!this.data.logged && e.detail.userInfo) { + this.setData({ + logged: true, + avatarUrl: e.detail.userInfo.avatarUrl, + userInfo: e.detail.userInfo, + hasUserInfo: true, + }) + } + }, + + onGetOpenid: function() { + // 调用云函数 + wx.cloud.callFunction({ + name: 'login', + data: {}, + success: res => { + console.log('[云函数] [login] user openid: ', res.result.openid) + app.globalData.openid = res.result.openid + wx.navigateTo({ + url: '../userConsole/userConsole', + }) + }, + fail: err => { + console.error('[云函数] [login] 调用失败', err) + wx.navigateTo({ + url: '../deployFunctions/deployFunctions', + }) + } + }) + }, + + // 上传图片 + doUpload: function () { + // 选择图片 + wx.chooseImage({ + count: 1, + sizeType: ['compressed'], + sourceType: ['album', 'camera'], + success: function (res) { + wx.showLoading({ + title: '上传中', + }) + + const filePath = res.tempFilePaths[0] + + // 上传图片 + const cloudPath = `my-image${filePath.match(/\.[^.]+?$/)[0]}` + wx.cloud.uploadFile({ + cloudPath, + filePath, + success: res => { + console.log('[上传文件] 成功:', res) + + app.globalData.fileID = res.fileID + app.globalData.cloudPath = cloudPath + app.globalData.imagePath = filePath + + wx.navigateTo({ + url: '../storageConsole/storageConsole' + }) + }, + fail: e => { + console.error('[上传文件] 失败:', e) + wx.showToast({ + icon: 'none', + title: '上传失败', + }) + }, + complete: () => { + wx.hideLoading() + } + }) + }, + fail: e => { + console.error(e) + } + }) + }, + +}) diff --git a/miniprogram/pages/index/index.json b/miniprogram/pages/index/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/miniprogram/pages/index/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml new file mode 100644 index 0000000..7b060a2 --- /dev/null +++ b/miniprogram/pages/index/index.wxml @@ -0,0 +1,6 @@ + + + +发现 + + diff --git a/miniprogram/pages/index/index.wxss b/miniprogram/pages/index/index.wxss new file mode 100644 index 0000000..85527b0 --- /dev/null +++ b/miniprogram/pages/index/index.wxss @@ -0,0 +1,161 @@ +/**index.wxss**/ + +page { + background: #f6f6f6; + display: flex; + flex-direction: column; + justify-content: flex-start; +} + +.userinfo, .uploader, .tunnel { + margin-top: 40rpx; + height: 140rpx; + width: 100%; + background: #fff; + border: 1px solid rgba(0, 0, 0, 0.1); + border-left: none; + border-right: none; + display: flex; + flex-direction: row; + align-items: center; + transition: all 300ms ease; +} + +.userinfo { + padding-left: 120rpx; +} + +.userinfo-avatar { + width: 100rpx; + height: 100rpx; + margin: 20rpx; + border-radius: 50%; + background-size: cover; + background-color: white; +} + +.userinfo-block-avatar { + width: 100rpx; + height: 100rpx; + margin: 20rpx; + border-radius: 50%; + overflow: hidden; +} + +.userinfo-avatar[size] { + width: 100rpx; +} + + +.userinfo-avatar:after { + border: none; +} + +.userinfo-nickname { + font-size: 32rpx; + color: #007aff; + background-color: white; + background-size: cover; + text-align: left; + padding-left: 0; + margin-left: 10px; +} + +.userinfo-nickname::after { + border: none; +} + +.userinfo-nickname-wrapper { + flex: 1; +} + +.uploader, .tunnel { + height: auto; + padding: 0 0 0 40rpx; + flex-direction: column; + align-items: flex-start; + box-sizing: border-box; +} + +.uploader-text, .tunnel-text { + width: 100%; + line-height: 52px; + font-size: 34rpx; + color: #007aff; +} + +.uploader-container { + width: 100%; + height: 400rpx; + padding: 20rpx 20rpx 20rpx 0; + display: flex; + align-content: center; + justify-content: center; + box-sizing: border-box; + border-top: 1px solid rgba(0, 0, 0, 0.1); +} + +.uploader-image { + width: 100%; + height: 360rpx; +} + +.tunnel { + padding: 0 0 0 40rpx; +} + +.tunnel-text { + position: relative; + color: #222; + display: flex; + flex-direction: row; + align-content: center; + justify-content: space-between; + box-sizing: border-box; + border-top: 1px solid rgba(0, 0, 0, 0.1); +} + +.tunnel-text:first-child { + border-top: none; +} + +.tunnel-switch { + position: absolute; + right: 20rpx; + top: -2rpx; +} + +.disable { + color: #888; +} + +.service { + position: fixed; + right: 40rpx; + bottom: 40rpx; + width: 140rpx; + height: 140rpx; + border-radius: 50%; + background: linear-gradient(#007aff, #0063ce); + box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3); + display: flex; + align-content: center; + justify-content: center; + transition: all 300ms ease; +} + +.service-button { + position: absolute; + top: 40rpx; +} + +.service:active { + box-shadow: none; +} + +.request-text { + padding: 20rpx 0; + font-size: 24rpx; + line-height: 36rpx; + word-break: break-all; +} diff --git a/miniprogram/pages/index/user-unlogin.png b/miniprogram/pages/index/user-unlogin.png new file mode 100644 index 0000000..95b27e4 Binary files /dev/null and b/miniprogram/pages/index/user-unlogin.png differ diff --git a/miniprogram/pages/more/more.js b/miniprogram/pages/more/more.js new file mode 100644 index 0000000..90868ed --- /dev/null +++ b/miniprogram/pages/more/more.js @@ -0,0 +1,51 @@ +// miniprogram/pages/more/more.js +const db = wx.cloud.database(); +Page({ + + /** + * 页面的初始数据 + */ + data: { + list:[] + }, + sliderto:function(e){ + var url=e.currentTarget.dataset.url + wx.navigateTo({ + url: '/pages/webview/webview?url=' + url, + }) + }, + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + const that = this; + wx.showLoading({ + title: '加载中', + }) + + if(options.model){ + var list = JSON.parse(options.model) + this.setData({ + list: list + }) + wx.hideLoading(); + return + } + db.collection('recommend').orderBy('index','asc').where({ + isfirst:options.isfirst + }).get({ + success: function(res) { + // res.data 是一个包含集合中有权限访问的所有记录的数据,不超过 20 条 + console.log(res.data) + that.setData({ + list: res.data + }) + wx.hideLoading(); + } + }) + + + }, + gotocompete:function(e){ + }, +}) \ No newline at end of file diff --git a/miniprogram/pages/more/more.json b/miniprogram/pages/more/more.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/miniprogram/pages/more/more.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/pages/more/more.wxml b/miniprogram/pages/more/more.wxml new file mode 100644 index 0000000..5d2f03c --- /dev/null +++ b/miniprogram/pages/more/more.wxml @@ -0,0 +1,16 @@ + + + + + + + {{item.title}} + + + {{item.note}} + + + + + diff --git a/miniprogram/pages/more/more.wxss b/miniprogram/pages/more/more.wxss new file mode 100644 index 0000000..f9fa4c1 --- /dev/null +++ b/miniprogram/pages/more/more.wxss @@ -0,0 +1,60 @@ +/* miniprogram/pages/more/more.wxss */ +page{ + background-color: #ccc; +} +.container2{ + width: 670rpx; + /* height: 700px; */ + margin: 0 40rpx; + /* background-color: aqua; */ +} +.list{ + width: 100%; + min-height: 400rpx; + margin-bottom: 30rpx; + background-color: white; + border-radius: 25rpx 25rpx 0 0; + overflow: hidden; +} +.list-img{ + width: 100%; + height: 300rpx; + border-radius: 25rpx 25rpx 0 0; +} +.list-img image{ + width: 100%; + height: 100%; + border-radius: 25rpx 25rpx 0 0; +} +.list-con-title{ + margin: 10rpx; + width: 100%; + height: 40rpx; + line-height: 40rpx; + font-size: 32rpx; + font-weight: 800; +} +.list-con-time{ + width: 100%; + max-width: 630rpx; + height: 40rpx; + margin: 10rpx 0; + line-height: 40rpx; + font-size: 28rpx; + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; +} +.list-con-icon{ + width: 30rpx; + height: 30rpx; + margin: 5rpx 10rpx; + display: inline-block; +} +.list-con-time2{ + display: inline-block; +} +.list-con-icon image{ + width: 100%; + height: 100%; +} \ No newline at end of file diff --git a/miniprogram/pages/my/my.js b/miniprogram/pages/my/my.js new file mode 100644 index 0000000..4e45c04 --- /dev/null +++ b/miniprogram/pages/my/my.js @@ -0,0 +1,178 @@ +// miniprogram/pages/my/my.js +const app = getApp(); +const dd=wx.cloud.database() +const db=wx.cloud.database().collection('user') +const db2=wx.cloud.database().collection('community') +Page({ + + /** + * 页面的初始数据 + */ + data: { + openid: '', + ismyfavor:"active", + isempty:false, + isvideoempty:true, + isother:'', + myfavor:[], + mycollect:[], + mycollect_video:[], + myfavor_video:[] + }, + go:function(){ + wx.switchTab({ + url: '../community/community', + }) + }, + menu_favor:function(){ + const that=this; + that.setData({ + ismyfavor:'active', + isother:'' + }) + console.log(that.data.myfavor) + + }, + menu_other:function(){ + const that=this; + that.setData({ + ismyfavor:'', + isother:'active', + }) + + + + }, + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + into:function(e){ + const that=this + var index=e.currentTarget.dataset.index + wx.navigateTo({ + url: '../detail/detail?content='+JSON.stringify(that.data.mycollect[index]), + }) + }, + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + const that=this + + that.setData({ + isempty:true, + isvideoempty:true + }) + wx.showLoading({ + title: '加载中...', + mask:true + }) + app.getOpenId.then(res => { + that.setData({ + openid:res + }) + + db.doc(res).get({ + success: function(res) { + console.log(res.data) + that.setData({ + myfavor:res.data.collect, + myfavor_video:res.data.collect_video + }) + console.log(res.data.collect.length) + if(res.data.collect.length!=0){ + that.setData({ + isempty:false, + }) + } + if(res.data.collect_video.length!=0){ + that.setData({ + isvideoempty:false, + }) + } + + const _=dd.command + db2.where({ + _id: _.in(that.data.myfavor) + }).get({ + success: function(res1) { + // res.data 是包含以上定义的两条记录的数组 + console.log(res1.data) + that.setData({ + mycollect:res1.data, + }) + + } + }) + dd.collection('video').where({ + _id: _.in(that.data.myfavor_video) + }).get({ + success: function(res1) { + // res.data 是包含以上定义的两条记录的数组 + console.log(res1.data) + that.setData({ + mycollect_video:res1.data, + }) + + } + }) + }, + fail:function(){ + that.setData({ + isempty:true, + isvideoempty:true + }) + } + }) + }) + wx.hideLoading({ + success: (res) => {}, + }) + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/miniprogram/pages/my/my.json b/miniprogram/pages/my/my.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/miniprogram/pages/my/my.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/pages/my/my.wxml b/miniprogram/pages/my/my.wxml new file mode 100644 index 0000000..4cd0c63 --- /dev/null +++ b/miniprogram/pages/my/my.wxml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + 帖子收藏 + 视频收藏 + + + + + + + 您还没有任何收藏~ + + 去逛逛 + + + + + + + + + {{'#'+item.type+'-'+item.recycle.obj_name+'*'+item.recycle.obj_num+':'+item.recycle.obj_price}}\n + + + {{'#'+item.type+'-'+item.partjob.unit+'-'+item.partjob.name}}\n + + {{'#'+item.type+'-'+item.college}}\n + + + + + + {{'#'+item.type}} + + + + + diff --git a/miniprogram/pages/my/my.wxss b/miniprogram/pages/my/my.wxss new file mode 100644 index 0000000..c60c1e3 --- /dev/null +++ b/miniprogram/pages/my/my.wxss @@ -0,0 +1,140 @@ +/* miniprogram/pages/my/my.wxss */ +page{ + background-color: #fff; +} +.container{ + position: absolute; + width: 100%; + height: 100%; + background-color: #FBF8F3; +} +.top{ + position: relative; + margin-top: 50rpx; +} +.top>view{ + display: inline-block; +} +.t_content{ + margin-top: 20rpx; + margin-left: 200rpx; + max-width: 60%; + max-height: 200rpx; + overflow: hidden; +} +.name{ + font-weight: 700; +} +.profile{ + margin-top: 10rpx; + font-size: 20rpx; +} +.h-cut{ + position: absolute; + margin-left: 50rpx; + border-radius: 50%; + width: 100rpx; + height: 100rpx; + overflow: hidden; +} +.h-cut image{ + width: 100%; + height: 100%; +} +.main{ + position: absolute; + padding: 20rpx; + bottom: 0; + left: 0; + right: 0; + height: 75%; + border-top-left-radius: 20rpx; + border-top-right-radius: 20rpx; + background-color: #fff; +} +.m-menu{ + border-radius: 20rpx; + width: fit-content; + overflow: hidden; +} +.active{ + background-color: #F4CA2B!important; + color:#FFF +} +.m-menu>view{ + display: inline-block; + text-align: center; + width: 150rpx; + height: 70rpx; + line-height: 70rpx; + background-color: #ddd; + font-size: 25rpx; +} +.empty{ + margin-top: 200rpx; +} +.empty >view{ + text-align: center; + margin: 30rpx auto; +} +.e-icon{ + width: 150rpx; + height: 150rpx; +} +.e-icon image{ + width: 100%; + height: 100%; +} +.e-title{ + font-size: 25rpx; +} +.btn-go{ + border-radius: 20rpx; + width: 150rpx; + height: 60rpx; + line-height: 60rpx; + background-color: #F4CA2B; + color: #FFF; +} +.full{ + display: flex; + flex-wrap: wrap; + justify-content: space-between; +} +.f-container{ + display: inline-block; + margin: 30rpx; + width: 250rpx; + height: 250rpx; +} +.f-img{ + border-radius: 20rpx; + overflow: hidden; + width: 250rpx; + height: 200rpx; +} +.f-img image{ + width: 100%; + height: 100%; +} +.f-content{ + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + text-align: center; + font-size: 25rpx; + height: 70rpx; +} +.video{ + margin-top: 20rpx; +} +.title{ + font-weight: 700; + color: rgb(49, 163, 230); +} +.video video{ + margin: 20rpx 0; +} +.video video{ + width: 100%; +} \ No newline at end of file diff --git a/miniprogram/pages/publish/publish.js b/miniprogram/pages/publish/publish.js new file mode 100644 index 0000000..90cd949 --- /dev/null +++ b/miniprogram/pages/publish/publish.js @@ -0,0 +1,308 @@ +// miniprogram/pages/publish/publish.js +const app = getApp(); +var util = require('../../utils/util.js') +const db = wx.cloud.database().collection('community') +Page({ + data: { + openid:'', + array: [], + photo_src:'', + fileID:'', + userInfo: {}, + hasUserInfo: false, + canIUseGetUserProfile:false, + type:"", + recycle:{ + obj_name:'', + obj_num:'', + obj_price:'', + obj_address:'', + obj_contact:'', + obj_note:'' + }, + partjob:{ + unit:"", + name:'', + time:'', + address:'', + content:"", + require:'', + salary:'', + sign_way:'', + note:'' + }, + college:'', + }, + bindPickerChange: function(e) { + this.setData({ + index: e.detail.value + }) + }, + upload:function(e){ + const that=this; + wx.chooseImage({ + count: 1, + success(res){ + console.log(res.tempFilePaths[0]) + that.setData({ + photo_src:res.tempFilePaths[0] + }) + wx.showLoading({ + title: '上传中...', + }) + var _time = util.formatTime(new Date()) + wx.cloud.uploadFile({ + cloudPath:'gzy/'+_time+that.data.openid, + filePath:res.tempFilePaths[0], + success(res){ + console.log(res) + that.setData({ + fileID:res.fileID + }) + wx.hideLoading() + wx.showToast({ + title: '上传成功!', + }) + } + }) + } + }) + }, + formSubmit(e){ + const that=this + + if(!e.detail.value.type){ + wx.showToast({ + title: '请选择标题', + icon: 'none', + }) + return + } + //判断类型 + if(that.data.type=='recycle'){ + + if(!e.detail.value.obj_name||!e.detail.value.obj_num||!e.detail.value.obj_price + ||!e.detail.value.obj_address||!e.detail.value.obj_contact){ + wx.showToast({ + title: '请填写完整信息!', + icon: 'none', + }) + return + }else{ + wx.showModal({ + title: '提示', + content: '确认发布吗?', + success (res) { + if (res.confirm) { + console.log('用户点击确定') + console.log(that.data.userInfo) + var _time = util.formatTime(new Date()) + db.add({ + data:{ + username:that.data.userInfo.nickName, + headcut:that.data.userInfo.avatarUrl, + type:'二手闲置', + z_type:that.data.array[e.detail.value.type], + img:that.data.fileID, + recycle:{ + obj_name:e.detail.value.obj_name, + obj_num:e.detail.value.obj_num, + obj_price:e.detail.value.obj_price, + obj_address:e.detail.value.obj_address, + obj_contact:e.detail.value.obj_contact, + obj_note:e.detail.value.obj_note + }, + date:_time, + comment:0, + like:0, + collect_num:0 + } + }).then(res => { + wx.showToast({ + title: '发布成功', + }) + that.setData({ + recycle:{ + obj_name:'', + obj_num:'', + obj_price:'', + obj_address:'', + obj_contact:'', + obj_note:'' + }, + }) + setTimeout(function () { + wx.navigateBack({ + delta: 1, + }) + }, 1000) + }) + } else if (res.cancel) { + console.log('用户点击取消') + } + } + }) + } + }else if(that.data.type=='partjob'){ + + if(!e.detail.value.unit||!e.detail.value.name||!e.detail.value.time||!e.detail.value.address + ||!e.detail.value.content||!e.detail.value.require||!e.detail.value.salary||!e.detail.value.sign_way){ + wx.showToast({ + title: '请填写完整信息!', + icon: 'none', + }) + return + }else{ + wx.showModal({ + title: '提示', + content: '确认发布吗?', + success (res) { + if (res.confirm) { + console.log('用户点击确定') + console.log(that.data.userInfo) + var _time = util.formatTime(new Date()) + db.add({ + data:{ + username:that.data.userInfo.nickName, + headcut:that.data.userInfo.avatarUrl, + type:'兼职实习', + z_type:that.data.array[e.detail.value.type], + img:that.data.fileID, + partjob:{ + unit:e.detail.value.unit, + name:e.detail.value.name, + time:e.detail.value.time, + address:e.detail.value.address, + content:e.detail.value.content, + require:e.detail.value.require, + salary:e.detail.value.salary, + sign_way:e.detail.value.sign_way, + note:e.detail.value.note + }, + date:_time, + comment:0, + like:0, + collect_num:0 + } + }).then(res => { + wx.showToast({ + title: '发布成功', + }) + that.setData({ + partjob:{ + unit:"", + name:'', + time:'', + address:'', + content:"", + require:'', + salary:'', + sign_way:'', + note:'' + }, + }) + setTimeout(function () { + wx.navigateBack({ + delta: 1, + }) + }, 1000) + }) + } else if (res.cancel) { + console.log('用户点击取消') + } + } + }) + } + }else if(that.data.type=='college'){ + if(!e.detail.value.college){ + wx.showToast({ + title: '请填写完整信息!', + icon: 'none', + }) + return + }else{ + console.log(e) + wx.showModal({ + title: '提示', + content: '确认发布吗?', + success (res) { + if (res.confirm) { + console.log('用户点击确定') + console.log(that.data.userInfo) + var _time = util.formatTime(new Date()) + db.add({ + data:{ + username:that.data.userInfo.nickName, + headcut:that.data.userInfo.avatarUrl, + type:'校园资讯', + z_type:that.data.array[e.detail.value.type], + img:that.data.fileID, + college:e.detail.value.college, + date:_time, + comment:0, + like:0, + collect_num:0 + } + }).then(res => { + wx.showToast({ + title: '发布成功', + }) + that.setData({ + college:'' + }) + setTimeout(function () { + wx.navigateBack({ + delta: 1, + }) + }, 1000) + }) + } else if (res.cancel) { + console.log('用户点击取消') + } + } + }) + } + } + }, + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + const that=this + that.setData({ + type:options.mode + }) + app.getOpenId.then(res => { + that.setData({ + openid:res + }) + }) + if (wx.getUserProfile) { + this.setData({ + canIUseGetUserProfile: true + }) + } + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + const that=this + if(that.data.type=="recycle"){ + that.setData({ + array:['出闲置','收闲置'] + }) + }else if(that.data.type=="partjob"){ + that.setData({ + array:['兼职招人','实习招人'] + }) + }else if(that.data.type=="college"){ + that.setData({ + array:['校园活动','校园产品','校园生活'] + }) + } + }, + + +}) \ No newline at end of file diff --git a/miniprogram/pages/publish/publish.json b/miniprogram/pages/publish/publish.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/miniprogram/pages/publish/publish.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/pages/publish/publish.wxml b/miniprogram/pages/publish/publish.wxml new file mode 100644 index 0000000..27c65c3 --- /dev/null +++ b/miniprogram/pages/publish/publish.wxml @@ -0,0 +1,53 @@ + + +
+ + + 标题:{{array[index]}} + + + + 物品名称: + 数量(个): + 价格(¥): + 交易地点: + 联系方式: + + + + + + 工作单位: + 岗位名称: + 工作时间: + 工作地点: + 工作内容: + + + 工作要求: + + + + 薪资及发放方式: + 报名方式: + + + + + + + + + + + + + + + + 上传图片 + + +
+ +
diff --git a/miniprogram/pages/publish/publish.wxss b/miniprogram/pages/publish/publish.wxss new file mode 100644 index 0000000..63065e3 --- /dev/null +++ b/miniprogram/pages/publish/publish.wxss @@ -0,0 +1,84 @@ +/* miniprogram/pages/publish/publish.wxss */ +.container2{ + padding: 30rpx 0; + font-weight: 600; +} +.input1{ + display: flex; + margin-bottom: 30rpx; + height: 90rpx; + padding: 13px; + background-color: #FFFFFF; + border-radius: 20rpx; + border: 1px solid #ddd; + box-sizing: border-box; + font-size: 30rpx; +} + +.input1 input{ + flex:1 +} +.input2{ + margin-bottom: 30rpx; + padding: 13px; + background-color: #FFFFFF; + border-radius: 20rpx; + border: 1px solid #ddd; + box-sizing: border-box; + font-size: 30rpx; +} +.input2 textarea{ + margin-top: 20rpx; +} +.message{ + margin-bottom: 30rpx; + width: 100%; + height: 500rpx; + border: 1px solid #ddd; + border-radius: 20rpx; + background-color: #FFFFFF; +} +.picker{ + margin-bottom: 30rpx; + position: relative; + padding: 13px; + background-color: #FFFFFF; + border-radius: 20rpx; + border: 1px solid #ddd; + box-sizing: border-box; + font-size: 30rpx; +} +.picker::after{ + position: absolute; + right: 20rpx; + top: 35rpx; + border: 15rpx solid transparent; + border-top: 20rpx solid #000; + content: ""; +} +.upload{ + margin: 0 auto; + width: 200rpx; + height: 100rpx; + line-height: 100rpx; + font-size: 30rpx; + color: #8c8c8c; +} +.upload image{ + width: 40%; + height: 50%; +} +.photo{ + width: 100%; +} +.submit{ + padding: 0!important; + margin: 50rpx auto; + width: 200rpx; + height: 80rpx; + line-height: 80rpx!important; + border-radius: 20rpx; + color: #fff; + background-color: #169BD5; + text-align: center; +} \ No newline at end of file diff --git a/miniprogram/pages/webview/webview.js b/miniprogram/pages/webview/webview.js new file mode 100644 index 0000000..07be076 --- /dev/null +++ b/miniprogram/pages/webview/webview.js @@ -0,0 +1,68 @@ +// miniprogram/pages/webview/webview.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + url:'' + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + this.setData({ + url:options.url // 通过传参实现跳转公众号推文 + }) + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/miniprogram/pages/webview/webview.json b/miniprogram/pages/webview/webview.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/miniprogram/pages/webview/webview.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/miniprogram/pages/webview/webview.wxml b/miniprogram/pages/webview/webview.wxml new file mode 100644 index 0000000..d05d6f8 --- /dev/null +++ b/miniprogram/pages/webview/webview.wxml @@ -0,0 +1,2 @@ + + diff --git a/miniprogram/pages/webview/webview.wxss b/miniprogram/pages/webview/webview.wxss new file mode 100644 index 0000000..d6e09e4 --- /dev/null +++ b/miniprogram/pages/webview/webview.wxss @@ -0,0 +1 @@ +/* miniprogram/pages/webview/webview.wxss */ \ No newline at end of file diff --git a/miniprogram/sitemap.json b/miniprogram/sitemap.json new file mode 100644 index 0000000..27b2b26 --- /dev/null +++ b/miniprogram/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git a/miniprogram/style/guide.wxss b/miniprogram/style/guide.wxss new file mode 100644 index 0000000..5a77414 --- /dev/null +++ b/miniprogram/style/guide.wxss @@ -0,0 +1,144 @@ +page { + background: #f6f6f6; + display: flex; + flex-direction: column; + justify-content: flex-start; +} + +.list { + margin-top: 40rpx; + height: auto; + width: 100%; + background: #fff; + padding: 0 40rpx; + border: 1px solid rgba(0, 0, 0, 0.1); + border-left: none; + border-right: none; + transition: all 300ms ease; + display: flex; + flex-direction: column; + align-items: stretch; + box-sizing: border-box; +} + +.list-item { + width: 100%; + padding: 0; + line-height: 104rpx; + font-size: 34rpx; + color: #007aff; + border-top: 1px solid rgba(0, 0, 0, 0.1); + display: flex; + flex-direction: row; + align-content: center; + justify-content: space-between; + box-sizing: border-box; +} + +.list-item:first-child { + border-top: none; +} + +.list-item image { + max-width: 100%; + max-height: 20vh; + margin: 20rpx 0; +} + +.request-text { + color: #222; + padding: 20rpx 0; + font-size: 24rpx; + line-height: 36rpx; + word-break: break-all; +} + +.guide { + width: 100%; + padding: 40rpx; + box-sizing: border-box; + display: flex; + flex-direction: column; +} + +.guide .headline { + font-size: 34rpx; + font-weight: bold; + color: #555; + line-height: 40rpx; +} + +.guide .p { + margin-top: 20rpx; + font-size: 28rpx; + line-height: 36rpx; + color: #666; +} + +.guide .code { + margin-top: 20rpx; + font-size: 28rpx; + line-height: 36rpx; + color: #666; + background: white; + white-space: pre; +} + +.guide .code-dark { + margin-top: 20rpx; + background: rgba(0, 0, 0, 0.8); + padding: 20rpx; + font-size: 28rpx; + line-height: 36rpx; + border-radius: 6rpx; + color: #fff; + white-space: pre +} + +.guide image { + max-width: 100%; +} + +.guide .image1 { + margin-top: 20rpx; + max-width: 100%; + width: 356px; + height: 47px; +} + +.guide .image2 { + margin-top: 20rpx; + width: 264px; + height: 100px; +} + +.guide .flat-image { + height: 100px; +} + +.guide .code-image { + max-width: 100%; +} + +.guide .copyBtn { + width: 180rpx; + font-size: 20rpx; + margin-top: 16rpx; + margin-left: 0; +} + +.guide .nav { + margin-top: 50rpx; + display: flex; + flex-direction: row; + align-content: space-between; +} + +.guide .nav .prev { + margin-left: unset; +} + +.guide .nav .next { + margin-right: unset; +} + diff --git a/miniprogram/utils/util.js b/miniprogram/utils/util.js new file mode 100644 index 0000000..74b7094 --- /dev/null +++ b/miniprogram/utils/util.js @@ -0,0 +1,75 @@ +const formatTime = date => { + const year = date.getFullYear() + const month = date.getMonth() + 1 + const day = date.getDate() + const hour = date.getHours() + const minute = date.getMinutes() + const second = date.getSeconds() + + return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` +} +const formatDate = date =>{ + const year = date.getFullYear() + const month = date.getMonth() + 1 + const day = date.getDate() + return `${[year, month, day].map(formatNumber).join('-')}` +} +const formatTime_a = date =>{ + const hour = date.getHours() + const minute = date.getMinutes() + return `${[hour, minute].map(formatNumber).join(':')}` +} +const formatNumber = n => { + n = n.toString() + return n[1] ? n : `0${n}` +} +const getend = later =>{ + let currentdate = new Date(); + currentdate.setDate(currentdate.getDate() + later); + return formatDate(currentdate) +} +function getDateDiff(dateTime) { + let dateTimeStamp = new Date(dateTime).getTime(); + let result = ''; + let minute = 1000 * 60; + let hour = minute * 60; + let day = hour * 24; + let halfamonth = day * 15; + let month = day * 30; + let year = day * 365; + let now = new Date().getTime(); + let diffValue = now - dateTimeStamp; + if (diffValue < 0) { + return; + } + let monthEnd = diffValue / month; + let weekEnd = diffValue / (7 * day); + let dayEnd = diffValue / day; + let hourEnd = diffValue / hour; + let minEnd = diffValue / minute; + let yearEnd = diffValue / year; + if (yearEnd >= 1) { + result = dateTime; + } else if (monthEnd >= 1) { + result = dateTime; + } else if (dayEnd >= 4) { + result = dateTime; + } else if ((dayEnd >= 1)&&(dayEnd<=3)){ + result = "" + parseInt(dayEnd) + "天前"; + } else if (hourEnd >= 1) { + result = "" + parseInt(hourEnd) + "小时前"; + } else if (minEnd >= 1) { + result = "" + parseInt(minEnd) + "分钟前"; + } else { + result = "刚刚"; + } + return result; +} + +module.exports = { + formatTime, + formatDate, + getend, + formatTime_a, + getDateDiff: getDateDiff +} diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..e028aa6 --- /dev/null +++ b/project.config.json @@ -0,0 +1,135 @@ +{ + "miniprogramRoot": "miniprogram/", + "cloudfunctionRoot": "cloudfunctions/", + "setting": { + "urlCheck": false, + "es6": true, + "enhance": true, + "postcss": true, + "preloadBackgroundData": false, + "minified": true, + "newFeature": true, + "coverView": true, + "nodeModules": false, + "autoAudits": false, + "showShadowRootInWxmlPanel": true, + "scopeDataCheck": false, + "uglifyFileName": false, + "checkInvalidKey": true, + "checkSiteMap": true, + "uploadWithSourceMap": true, + "compileHotReLoad": false, + "useMultiFrameRuntime": true, + "useApiHook": true, + "useApiHostProcess": true, + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "useIsolateContext": true, + "userConfirmedBundleSwitch": false, + "packNpmManually": false, + "packNpmRelationList": [], + "minifyWXSS": true, + "showES6CompileOption": false, + "condition": false + }, + "appid": "wx3647b7d4bda47af5", + "projectname": "gzyjsjlpt", + "libVersion": "2.14.1", + "simulatorType": "wechat", + "simulatorPluginLibVersion": {}, + "condition": { + "search": { + "list": [] + }, + "conversation": { + "list": [] + }, + "plugin": { + "list": [] + }, + "game": { + "list": [] + }, + "gamePlugin": { + "list": [] + }, + "miniprogram": { + "list": [ + { + "id": -1, + "name": "db guide", + "pathName": "pages/databaseGuide/databaseGuide", + "query": "" + }, + { + "id": -1, + "name": "pages/find/find", + "pathName": "pages/find/find", + "query": "", + "scene": null + }, + { + "id": -1, + "name": "pages/index/index", + "pathName": "pages/index/index", + "query": "", + "scene": null + }, + { + "id": -1, + "name": "pages/community/community", + "pathName": "pages/community/community", + "query": "", + "scene": null + }, + { + "id": -1, + "name": "pages/publish/publish", + "pathName": "pages/publish/publish", + "query": "", + "scene": null + }, + { + "id": -1, + "name": "pages/detail/detail", + "pathName": "pages/detail/detail", + "query": "", + "scene": null + }, + { + "id": -1, + "name": "pages/my/my", + "pathName": "pages/my/my", + "query": "", + "scene": null + }, + { + "id": -1, + "name": "pages/search/search", + "pathName": "pages/search/search", + "query": "", + "scene": null + }, + { + "id": -1, + "name": "pages/compete/compete", + "pathName": "pages/compete/compete", + "scene": null + } + ] + } + }, + "compileType": "miniprogram", + "srcMiniprogramRoot": "miniprogram/", + "packOptions": { + "ignore": [], + "include": [] + }, + "editorSetting": { + "tabIndent": "insertSpaces", + "tabSize": 2 + } +} \ No newline at end of file diff --git a/project.private.config.json b/project.private.config.json new file mode 100644 index 0000000..3210eb0 --- /dev/null +++ b/project.private.config.json @@ -0,0 +1,60 @@ +{ + "setting": { + "compileHotReLoad": true + }, + "condition": { + "miniprogram": { + "list": [ + { + "name": "db guide", + "pathName": "pages/databaseGuide/databaseGuide", + "query": "" + }, + { + "name": "pages/more/more", + "pathName": "pages/more/more", + "query": "", + "scene": null + }, + { + "name": "pages/compete/compete", + "pathName": "pages/compete/compete", + "query": "", + "scene": null + }, + { + "name": "pages/community/community", + "pathName": "pages/community/community", + "query": "", + "scene": null + }, + { + "name": "pages/publish/publish", + "pathName": "pages/publish/publish", + "query": "", + "scene": null + }, + { + "name": "pages/choose/choose", + "pathName": "pages/choose/choose", + "query": "", + "scene": null + }, + { + "name": "pages/my/my", + "pathName": "pages/my/my", + "query": "", + "scene": null + }, + { + "name": "pages/find/find", + "pathName": "pages/find/find", + "query": "", + "scene": null + } + ] + } + }, + "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", + "projectname": "gzyjlpt-master" +} \ No newline at end of file