commit f9b148ca8ac3156f57dc7fd8c8bedc2627529370 Author: itgaojian163 Date: Fri Dec 27 17:08:36 2024 +0800 初始化 diff --git a/app.js b/app.js new file mode 100644 index 0000000..cf443c5 --- /dev/null +++ b/app.js @@ -0,0 +1,21 @@ +// app.js +const request = require('./utils/http.js'); + +App({ + onLaunch() { + // 展示本地存储能力 + const logs = wx.getStorageSync('logs') || [] + logs.unshift(Date.now()) + wx.setStorageSync('logs', logs) + + // 登录 + wx.login({ + success: res => { + // 发送 res.code 到后台换取 openId, sessionKey, unionId + } + }) + }, + globalData: { + userInfo: null + } +}) \ No newline at end of file diff --git a/app.json b/app.json new file mode 100644 index 0000000..7508301 --- /dev/null +++ b/app.json @@ -0,0 +1,14 @@ +{ + "pages": [ + "pages/index/index" + ], + "window": { + "navigationBarTextStyle": "black", + "navigationBarTitleText": "Weixin", + "navigationBarBackgroundColor": "#ffffff" + }, + "style": "v2", + "componentFramework": "glass-easel", + "sitemapLocation": "sitemap.json", + "lazyCodeLoading": "requiredComponents" +} diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..06c6fc9 --- /dev/null +++ b/app.wxss @@ -0,0 +1,10 @@ +/**app.wxss**/ +.container { + height: 100%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: space-between; + padding: 200rpx 0; + box-sizing: border-box; +} diff --git a/components/empty/empty.js b/components/empty/empty.js new file mode 100644 index 0000000..9fe184b --- /dev/null +++ b/components/empty/empty.js @@ -0,0 +1,23 @@ +// components/empty/empty.js +Component({ + /** + * 组件的属性列表 + */ + properties: { + + }, + + /** + * 组件的初始数据 + */ + data: { + + }, + + /** + * 组件的方法列表 + */ + methods: { + + } +}) diff --git a/components/empty/empty.json b/components/empty/empty.json new file mode 100644 index 0000000..7e37c03 --- /dev/null +++ b/components/empty/empty.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/components/empty/empty.wxml b/components/empty/empty.wxml new file mode 100644 index 0000000..5c056ae --- /dev/null +++ b/components/empty/empty.wxml @@ -0,0 +1,5 @@ + + + + 暂无数据 + \ No newline at end of file diff --git a/components/empty/empty.wxss b/components/empty/empty.wxss new file mode 100644 index 0000000..d7792cf --- /dev/null +++ b/components/empty/empty.wxss @@ -0,0 +1,24 @@ +/* components/empty/empty.wxss */ +.data-empty { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + text-align: center; + align-self: center; + + position: fixed; + top: 50%; + left: 50%; + transform: translateX(-50%)translateY(-50%); +} + +.data-empty image { + width: 180rpx; + height: 120rpx; +} + +.data-empty .hint { + margin-top: 30rpx; + font-size: 32rpx; +} \ No newline at end of file diff --git a/components/loading/pageloading.js b/components/loading/pageloading.js new file mode 100644 index 0000000..7c20516 --- /dev/null +++ b/components/loading/pageloading.js @@ -0,0 +1,23 @@ +// components/loading/pageloading.js +Component({ + /** + * 组件的属性列表 + */ + properties: { + + }, + + /** + * 组件的初始数据 + */ + data: { + + }, + + /** + * 组件的方法列表 + */ + methods: { + + } +}) diff --git a/components/loading/pageloading.json b/components/loading/pageloading.json new file mode 100644 index 0000000..e8cfaaf --- /dev/null +++ b/components/loading/pageloading.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/components/loading/pageloading.wxml b/components/loading/pageloading.wxml new file mode 100644 index 0000000..2115a2b --- /dev/null +++ b/components/loading/pageloading.wxml @@ -0,0 +1,5 @@ + + + + 加载中... + \ No newline at end of file diff --git a/components/loading/pageloading.wxss b/components/loading/pageloading.wxss new file mode 100644 index 0000000..f36fd23 --- /dev/null +++ b/components/loading/pageloading.wxss @@ -0,0 +1,24 @@ +/* components/loading/pageloading.wxss */ +.page-loading-box { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + /* background: rgba(255, 255, 255, 1); */ + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + z-index: 99; +} + +.page-loading-box image { + width: 128rpx; + height: 128rpx; +} + +.page-loading-box .text { + margin-top: 20rpx; + font-size: 28rpx; +} \ No newline at end of file diff --git a/components/loadmore/loading-more.js b/components/loadmore/loading-more.js new file mode 100644 index 0000000..b2eec0f --- /dev/null +++ b/components/loadmore/loading-more.js @@ -0,0 +1,30 @@ +// components/loadmore/loading-more.js +Component({ + /** + * 组件的属性列表 + */ + properties: { + isShowloading: true, + loadingTxt: "加载中..." + }, + + /** + * 组件的初始数据 + */ + data: { + + }, + + /** + * 组件的方法列表 + */ + methods: { + + }, + observers: { + 'isShowloading,loadingTxt': function (ss, sss) { + console.log(ss) + console.log(sss) + } + } +}) \ No newline at end of file diff --git a/components/loadmore/loading-more.json b/components/loadmore/loading-more.json new file mode 100644 index 0000000..7e37c03 --- /dev/null +++ b/components/loadmore/loading-more.json @@ -0,0 +1,4 @@ +{ + "component": true, + "usingComponents": {} +} \ No newline at end of file diff --git a/components/loadmore/loading-more.wxml b/components/loadmore/loading-more.wxml new file mode 100644 index 0000000..f67005c --- /dev/null +++ b/components/loadmore/loading-more.wxml @@ -0,0 +1,5 @@ + + + + {{loadingTxt}} + \ No newline at end of file diff --git a/components/loadmore/loading-more.wxss b/components/loadmore/loading-more.wxss new file mode 100644 index 0000000..b29e480 --- /dev/null +++ b/components/loadmore/loading-more.wxss @@ -0,0 +1,20 @@ +/* components/loadmore/loading-more.wxss */ + +.loading-box { + width: 100%; + height: 80rpx; + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + font-size: 35rpx; +} + +.loading-box image { + width: 40rpx; + height: 40rpx; +} + +.loading-content { + margin-left: 20rpx; +} \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js new file mode 100644 index 0000000..afd82da --- /dev/null +++ b/pages/index/index.js @@ -0,0 +1,56 @@ +// index.js +const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0' +var app = getApp(); + +Page({ + data: { + motto: 'Hello World', + userInfo: { + avatarUrl: defaultAvatarUrl, + nickName: '', + }, + hasUserInfo: false, + canIUseGetUserProfile: wx.canIUse('getUserProfile'), + canIUseNicknameComp: wx.canIUse('input.type.nickname'), + }, + bindViewTap() { + wx.navigateTo({ + url: '../logs/logs' + }) + }, + onChooseAvatar(e) { + const { + avatarUrl + } = e.detail + const { + nickName + } = this.data.userInfo + this.setData({ + "userInfo.avatarUrl": avatarUrl, + hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, + }) + }, + onInputChange(e) { + const nickName = e.detail.value + const { + avatarUrl + } = this.data.userInfo + this.setData({ + "userInfo.nickName": nickName, + hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, + }) + }, + getUserProfile(e) { + // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 + wx.getUserProfile({ + desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + console.log(res) + this.setData({ + userInfo: res.userInfo, + hasUserInfo: true + }) + } + }) + }, +}) \ No newline at end of file diff --git a/pages/index/index.json b/pages/index/index.json new file mode 100644 index 0000000..b55b5a2 --- /dev/null +++ b/pages/index/index.json @@ -0,0 +1,4 @@ +{ + "usingComponents": { + } +} \ No newline at end of file diff --git a/pages/index/index.wxml b/pages/index/index.wxml new file mode 100644 index 0000000..637743e --- /dev/null +++ b/pages/index/index.wxml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pages/index/index.wxss b/pages/index/index.wxss new file mode 100644 index 0000000..1ebed4b --- /dev/null +++ b/pages/index/index.wxss @@ -0,0 +1,62 @@ +/**index.wxss**/ +page { + height: 100vh; + display: flex; + flex-direction: column; +} +.scrollarea { + flex: 1; + overflow-y: hidden; +} + +.userinfo { + display: flex; + flex-direction: column; + align-items: center; + color: #aaa; + width: 80%; +} + +.userinfo-avatar { + overflow: hidden; + width: 128rpx; + height: 128rpx; + margin: 20rpx; + border-radius: 50%; +} + +.usermotto { + margin-top: 200px; +} + +.avatar-wrapper { + padding: 0; + width: 56px !important; + border-radius: 8px; + margin-top: 40px; + margin-bottom: 40px; +} + +.avatar { + display: block; + width: 56px; + height: 56px; +} + +.nickname-wrapper { + display: flex; + width: 100%; + padding: 16px; + box-sizing: border-box; + border-top: .5px solid rgba(0, 0, 0, 0.1); + border-bottom: .5px solid rgba(0, 0, 0, 0.1); + color: black; +} + +.nickname-label { + width: 105px; +} + +.nickname-input { + flex: 1; +} diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..55325de --- /dev/null +++ b/project.config.json @@ -0,0 +1,28 @@ +{ + "compileType": "miniprogram", + "libVersion": "trial", + "packOptions": { + "ignore": [], + "include": [] + }, + "setting": { + "coverView": true, + "es6": true, + "postcss": true, + "minified": true, + "enhance": true, + "showShadowRootInWxmlPanel": true, + "packNpmRelationList": [], + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + } + }, + "condition": {}, + "editorSetting": { + "tabIndent": "auto", + "tabSize": 2 + }, + "appid": "wx501e9ce64f25c418" +} \ No newline at end of file diff --git a/project.private.config.json b/project.private.config.json new file mode 100644 index 0000000..b4b90e6 --- /dev/null +++ b/project.private.config.json @@ -0,0 +1,7 @@ +{ + "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", + "projectname": "gov_propagandize", + "setting": { + "compileHotReLoad": true + } +} \ No newline at end of file diff --git a/sitemap.json b/sitemap.json new file mode 100644 index 0000000..ca02add --- /dev/null +++ b/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/utils/api/testapi.js b/utils/api/testapi.js new file mode 100644 index 0000000..f40593d --- /dev/null +++ b/utils/api/testapi.js @@ -0,0 +1,83 @@ +// 引入 request 文件 +import request from '@/utils/request'; + +// 以下 api 为示例,实际与项目相匹配 + +// 分页查询学习列表 +export const pageStudyInfo = (params) => { + return request({ + url: '/study/studyInfo/page', + method: 'GET', + data: params + }); +}; + +// 查询学习列表 +export const listStudyInfo = (params) => { + return request({ + url: '/study/studyInfo/list', + method: 'GET', + data: params + }); +}; + +// 获取学习列表详细信息 +export const studyInfoById = (id) => { + return request({ + url: `/study/studyInfo/${id}`, + method: 'GET', + }); +}; + +// 增加学习列表 +export const saveStudyInfo = (params) => { + return request({ + url: '/study/studyInfo', + method: 'POST', + data: params + }); +}; + +// 修改学习列表 +export const updateStudyInfo = (params) => { + return request({ + url: '/study/studyInfo', + method: 'PUT', + data: params + }); +}; + +// 删除学习列表 +export const deleteStudyInfo = (id) => { + return request({ + url: `/study/studyInfo/delete?id=${id}`, + method: 'DELETE', + }); +}; + + + + + + +// Page({ +// data: { +// studyList: [] +// }, + +// onLoad: function () { +// this.getStudyList(); +// }, + +// getStudyList: async function () { +// try { +// const res = await pageStudyInfo(this.data.queryParams); +// console.log(res.data.records); +// this.setData({ +// studyList: res.data.records +// }); +// } catch (error) { +// console.error(error); +// } +// } +// }); \ No newline at end of file diff --git a/utils/http.js b/utils/http.js new file mode 100644 index 0000000..a61fc07 --- /dev/null +++ b/utils/http.js @@ -0,0 +1,86 @@ +// 全局请求封装 +const base_url = 'http://localhost:996'; + +export default (params) => { + let url = params.url; + let method = params.method || "GET"; + let data = params.data || {}; + let header = {}; + + if (method == "POST") { + header = { + 'content-type': 'application/json' + }; + } + + // 获取本地token + const token = wx.getStorageSync("token"); + if (token) { + header['Authorization'] = 'Bearer ' + token; + } + + return new Promise((resolve, reject) => { + wx.request({ + url: base_url + url, + method: method, + header: header, + data: data, + success(response) { + const res = response.data; + if (res.statusCode == 200) { + resolve(res); + } else { + wx.clearStorageSync(); + switch (res.statusCode) { + case 401: + wx.showModal({ + title: "提示", + content: "请登录", + showCancel: false, + success(res) { + setTimeout(() => { + wx.navigateTo({ + url: "/pages/login/index", + }); + }, 1000); + }, + }); + break; + case 404: + wx.showToast({ + title: '请求地址不存在...', + duration: 2000, + }); + break; + default: + wx.showToast({ + title: '请重试...', + duration: 2000, + }); + break; + } + } + }, + fail(err) { + console.log(err); + if (err.errMsg.indexOf('request:fail') !== -1) { + wx.showToast({ + title: '网络异常', + icon: "error", + duration: 2000 + }); + } else { + wx.showToast({ + title: '未知异常', + duration: 2000 + }); + } + reject(err); + }, + complete() { + wx.hideLoading(); + wx.hideToast(); + } + }); + }).catch((e) => {}); +}; \ No newline at end of file diff --git a/utils/util.js b/utils/util.js new file mode 100644 index 0000000..f89d2be --- /dev/null +++ b/utils/util.js @@ -0,0 +1,32 @@ +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(':') +} + +/** + * + * @param {*} date + */ +const formatDate = date => { + const year = date.getFullYear() + const month = date.getMonth() + 1 + const day = date.getDate() + + return [year, month, day].map(formatNumber).join('-') +} + +const formatNumber = n => { + n = n.toString() + return n[1] ? n : '0' + n +} + +module.exports = { + formatTime: formatTime, + formatDate: formatDate +} \ No newline at end of file