commit 4a940f28bad1f4d3e192db2955efe58d9336bac7 Author: ckaaaa Date: Tue Sep 16 13:41:49 2025 +0800 feat: move project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..69148d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +node_modules/ +yarn-error.log +miniprogram/ +miniprogram_npm/ +miniprogram_dist/ +.DS_Store +$node_modules/ +.history/ +**/dist +components/**/*.lock +components/**/package-lock.json +package-lock.json +yarn.lock +project.private.config.json +.eslintcache \ No newline at end of file diff --git a/app.js b/app.js new file mode 100644 index 0000000..42037fe --- /dev/null +++ b/app.js @@ -0,0 +1,9 @@ +import updateManager from './common/updateManager'; + +App({ + onLaunch: function () { + }, + onShow: function () { + updateManager(); + }, +}); diff --git a/app.json b/app.json new file mode 100644 index 0000000..4914b7f --- /dev/null +++ b/app.json @@ -0,0 +1,53 @@ +{ + "pages": [ + "pages/home/home", + "pages/paylist/paylist", + "pages/news_list/home", + "pages/news_admin_list/home", + "pages/usercenter/index", + "pages/detail/detail", + "pages/detail_admin/detail", + "pages/takephoto/takephoto", + "pages/faxianlist/faxianlist", + "pages/test/test", + "pages/shop/shop", + "pages/pay/pay", + "pages/createpay/createpay", + "pages/sharebuy/sharebuy", + "pages/usercenter/info", + "pages/sharelist/sharelist", + "pages/webview/webview" + ], + "tabBar": { + "custom": true, + "color": "#666666", + "selectedColor": "#FF5F15", + "backgroundColor": "#ffffff", + "borderStyle": "black", + "list": [ + { + "pagePath": "pages/home/home", + "text": "首页" + }, + { + "pagePath": "pages/faxianlist/faxianlist", + "text": "分销" + }, + { + "pagePath": "pages/usercenter/index", + "text": "我的" + } + ] + }, + "requiredPrivateInfos": [], + "lazyCodeLoading": "requiredComponents", + "usingComponents": {}, + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "Weixin", + "navigationBarTextStyle": "black" + }, + "sitemapLocation": "sitemap.json", + "permission": {} +} \ No newline at end of file diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..9ff2554 --- /dev/null +++ b/app.wxss @@ -0,0 +1,3 @@ +@import 'style/iconfont.wxss'; + +@import 'style/theme.wxss'; \ No newline at end of file diff --git a/common/updateManager.js b/common/updateManager.js new file mode 100644 index 0000000..c45de6d --- /dev/null +++ b/common/updateManager.js @@ -0,0 +1,29 @@ +export default () => { + if (!wx.canIUse('getUpdateManager')) { + return; + } + + const updateManager = wx.getUpdateManager(); + + updateManager.onCheckForUpdate(function (res) { + // 请求完新版本信息的回调 + console.log('版本信息', res); + }); + + updateManager.onUpdateReady(function () { + wx.showModal({ + title: '更新提示', + content: '新版本已经准备好,是否重启应用?', + success(res) { + if (res.confirm) { + // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 + updateManager.applyUpdate(); + } + }, + }); + }); + + updateManager.onUpdateFailed(function () { + // 新版本下载失败 + }); +}; diff --git a/config/index.js b/config/index.js new file mode 100644 index 0000000..64fed65 --- /dev/null +++ b/config/index.js @@ -0,0 +1,4 @@ +export const config = { + /** 是否使用mock代替api返回 */ + useMock: true, +}; diff --git a/custom-tab-bar/data.js b/custom-tab-bar/data.js new file mode 100644 index 0000000..675c07f --- /dev/null +++ b/custom-tab-bar/data.js @@ -0,0 +1,16 @@ +export default [{ + icon: 'home', + text: '动态', + url: 'pages/home/home', +}, +{ + icon: 'share', + text: '分销', + url: 'pages/faxianlist/faxianlist', +}, +{ + icon: 'person', + text: '我的', + url: 'pages/usercenter/index', +}, +]; \ No newline at end of file diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js new file mode 100644 index 0000000..024eb95 --- /dev/null +++ b/custom-tab-bar/index.js @@ -0,0 +1,66 @@ +import TabMenu from './data'; +import R from '../utils/request'; +import C from '../utils/constant'; +Component({ + data: { + active: 0, + list: [], + is_share: false, + cdnHost: C.cdnHost, + }, + + ready() { + R.get('/index.php/api/v1/my').then(({ model }) => { + this.setData({ + is_share: !!model.is_share, + list: TabMenu.filter((_, idx) => { + if (model.is_share) { + return true + } else { + return idx !== 1 + } + }) + }); + }); + }, + + methods: { + goTakePhoto() { + wx.navigateTo({ + url: '/pages/takephoto/takephoto', + }) + }, + onChange(event) { + this.setData({ active: event.detail.value }); + wx.switchTab({ + url: this.data.list[event.detail.value].url.startsWith('/') + ? this.data.list[event.detail.value].url + : `/${this.data.list[event.detail.value].url}`, + }); + }, + + init() { + const page = getCurrentPages().pop(); + const route = page ? page.route.split('?')[0] : ''; + const active = this.data.list.findIndex( + (item) => + (item.url.startsWith('/') ? item.url.substr(1) : item.url) === + `${route}`, + ); + this.setData({ active }); + }, + getPhoneNumber(e) { + console.log(e.detail.code) // 动态令牌 + console.log(e.detail.errMsg) // 回调信息(成功失败都会返回) + console.log(e.detail.errno) // 错误码(失败时返回) + if (!e.detail.errno) { + R.post('/index.php/api/v1/bind_auth_phone', { code: e.detail.code }).then(() => { + this.setData({ hasPhone: true }) + this.goTakePhoto(); + }) + } else { + // e.detail.errMsg + } + }, + }, +}); diff --git a/custom-tab-bar/index.json b/custom-tab-bar/index.json new file mode 100644 index 0000000..eab5fb3 --- /dev/null +++ b/custom-tab-bar/index.json @@ -0,0 +1,9 @@ +{ + "component": true, + "usingComponents": { + "t-tab-bar": "tdesign-miniprogram/tab-bar/tab-bar", + "t-tab-bar-item": "tdesign-miniprogram/tab-bar-item/tab-bar-item", + "t-icon": "tdesign-miniprogram/icon/icon", + "t-image": "tdesign-miniprogram/image/image" + } +} \ No newline at end of file diff --git a/custom-tab-bar/index.wxml b/custom-tab-bar/index.wxml new file mode 100644 index 0000000..9900622 --- /dev/null +++ b/custom-tab-bar/index.wxml @@ -0,0 +1,36 @@ + + + + + + {{ item.text }} + + + + + + \ No newline at end of file diff --git a/custom-tab-bar/index.wxss b/custom-tab-bar/index.wxss new file mode 100644 index 0000000..e8b8bf4 --- /dev/null +++ b/custom-tab-bar/index.wxss @@ -0,0 +1,40 @@ +.tabline { + position: relative; +} + + +.custom-tab-bar-wrapper { + display: flex; + align-items: center; +} + +.text { + font-size: 28rpx; + padding-left: 10rpx; +} + +.camera { + position: absolute; + left: 50%; + top: 20rpx; + border-radius: 20rpx; + height: 78rpx; + width: 176rpx; + background: linear-gradient(180deg, rgb(74, 137, 254) 0%, rgb(47, 103, 254) 100%); + transform: translateX(-50%); + display: flex; + align-items: center; + justify-content: center; + z-index: 2; + font-size: 28rpx; + color: #fff; +} +.camera .txt{ + display: flex; + align-items: center; + padding-left:10rpx; + white-space: nowrap; +} +.custom-tab-bar-wrapper.cur { + color: #2966f5; +} \ No newline at end of file diff --git a/gitadd.bat b/gitadd.bat new file mode 100644 index 0000000..9410919 --- /dev/null +++ b/gitadd.bat @@ -0,0 +1,3 @@ +git add . +git commit -m "f" +git push \ No newline at end of file diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..36aa1a4 --- /dev/null +++ b/jsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "baseUrl": "." + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..b65e1e5 --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "@tencent/tdesign-miniprogram-starter-retail", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "dayjs": "^1.9.3", + "tdesign-miniprogram": "^1.4.0", + "tslib": "^1.11.1" + }, + "devDependencies": {} +} \ No newline at end of file diff --git a/pages/createpay/createpay.js b/pages/createpay/createpay.js new file mode 100644 index 0000000..3d417d0 --- /dev/null +++ b/pages/createpay/createpay.js @@ -0,0 +1,109 @@ +import C from '../../utils/constant'; +import * as F from '../../utils/func'; +import R from '../../utils/request'; +import ActionSheet, { ActionSheetTheme } from 'tdesign-miniprogram/action-sheet/index'; + +Page({ + data: { + price: '', + expireDate: F.parseDate(new Date()), + dateVisible: false, + start: F.parseDate(new Date()), + end: F.parseDate(new Date(new Date() * 1 + 24 * 3600 * 366 * 1000 + 1)), + filter(type, options) { + if (type === 'year') { + return options.sort((a, b) => b.value - a.value); + } + return options; + }, + popupProps: { + usingCustomNavbar: true, + }, + buy_type: '', + buy_types: [], + }, + onLoad() { + R.get('/index.php/api/v1/config_one', { k: 'buy_types' }).then(({ model }) => { + this.setData({ + buy_types: model || [], + buy_type: model[0], + }); + }); + }, + handleSelected(e) { + console.log(e.detail); + this.setData({ + buy_type: e.detail.selected.label, + }); + }, + handleAction() { + ActionSheet.show({ + theme: ActionSheetTheme.List, + selector: '#t-action-sheet', + context: this, + items: this.data.buy_types.map((item) => ({ + label: item, + })), + }); + }, + onConfirm(e) { + const { value } = e.detail; + this.setData({ + expireDate: value, + dateVisible: false, + }); + }, + showPicker() { + this.setData({ dateVisible: true }); + }, + onClose() { + this.setData({ dateVisible: false }); + }, + validate() { + const { price, expireDate } = this.data; + if (!price) { + wx.showToast({ title: '请输入分销金额', icon: 'none' }); + return false; + } + if (!/^\d+(\.\d+)?$/.test(price)) { + wx.showToast({ title: '请输入正确的金额', icon: 'none' }); + return false; + } + + if (!expireDate) { + wx.showToast({ title: '请选择付款有效期', icon: 'none' }); + return false; + } + return true; + }, + share() { + if (!this.validate()) return; + // TODO: 调用分享接口 + // console.log('share1', this.data); + // wx.showShareMenu({ + // withShareTicket: true, + // menus: ['shareAppMessage'] + // }); + }, + onShareAppMessage(e) { + if (!this.validate()) { + return { + title: '', + path: '', + imageUrl: '', + promise: Promise.reject(), + } + } + const { price, expireDate, buy_type } = this.data; + return R.get('/index.php/api/v1/create_share', { + price, expireDate, buy_type, + }).then(({ model }) => { + return { + title: model.title, + path: model.path || '/pages/sharebuy/sharebuy?id=' + model.id, + imageUrl: model.img, + promise: Promise.resolve(), + }; + }); + }, +}); \ No newline at end of file diff --git a/pages/createpay/createpay.json b/pages/createpay/createpay.json new file mode 100644 index 0000000..7d30697 --- /dev/null +++ b/pages/createpay/createpay.json @@ -0,0 +1,11 @@ +{ + "navigationBarTitleText": "分销", + "backgroundTextStyle": "light", + "usingComponents": { + "t-cell": "tdesign-miniprogram/cell/cell", + "t-button": "tdesign-miniprogram/button/button", + "t-input": "tdesign-miniprogram/input/input", + "t-date-time-picker": "tdesign-miniprogram/date-time-picker/date-time-picker", + "t-action-sheet": "tdesign-miniprogram/action-sheet/action-sheet" + } +} \ No newline at end of file diff --git a/pages/createpay/createpay.less b/pages/createpay/createpay.less new file mode 100644 index 0000000..e69de29 diff --git a/pages/createpay/createpay.wxml b/pages/createpay/createpay.wxml new file mode 100644 index 0000000..84f1af1 --- /dev/null +++ b/pages/createpay/createpay.wxml @@ -0,0 +1,14 @@ + + + + + + + + + + 分享 + + + + \ No newline at end of file diff --git a/pages/createpay/createpay.wxss b/pages/createpay/createpay.wxss new file mode 100644 index 0000000..95faadd --- /dev/null +++ b/pages/createpay/createpay.wxss @@ -0,0 +1,14 @@ +.container { + padding: 20rpx; +} + +.form { + background: #fff; + border-radius: 10rpx; + overflow: hidden; +} + +.footer { + margin-top: 40rpx; + padding: 0 20rpx; +} \ No newline at end of file diff --git a/pages/detail/detail.js b/pages/detail/detail.js new file mode 100644 index 0000000..6ea8d63 --- /dev/null +++ b/pages/detail/detail.js @@ -0,0 +1,33 @@ +import R from '../../utils/request'; +import C from '../../utils/constant'; +Page({ + + data: { + cdnHost: C.cdnHost, + detail: {}, + user: {}, + }, + onLoad(options) { + const { id } = options; + R.get('/index.php/api/v1/news_detail', { id }).then(({ model }) => { + this.setData({ + detail: { + ...model.detail, + content: (model.detail.content||'').replace(/src\="\/uploads/g, 'src="'+C.cdnHost + '/uploads'), + imgs: (model.detail.imgs || '').split(',').filter(o=>!!o), + video: model.detail.video ? model.detail.video : '', + }, + user: { + ...model.user, + } + }); + }); + }, + videoErrorCallback(e) { + console.log('视频错误信息:') + console.log(e.detail.errMsg) + }, + onShareAppMessage() { + + } +}) \ No newline at end of file diff --git a/pages/detail/detail.json b/pages/detail/detail.json new file mode 100644 index 0000000..edea912 --- /dev/null +++ b/pages/detail/detail.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "详情", + "backgroundTextStyle": "light", + "usingComponents": { + "t-icon": "tdesign-miniprogram/icon/icon", + "t-image": "tdesign-miniprogram/image/image" + } +} \ No newline at end of file diff --git a/pages/detail/detail.wxml b/pages/detail/detail.wxml new file mode 100644 index 0000000..c45712d --- /dev/null +++ b/pages/detail/detail.wxml @@ -0,0 +1,14 @@ + + {{detail.title}} + + {{detail.create_time}} + + + {{detail.view_cnt}} + + + + + + 来源: {{user.real_name || '三鲤'}} + \ No newline at end of file diff --git a/pages/detail/detail.wxss b/pages/detail/detail.wxss new file mode 100644 index 0000000..c19bf5d --- /dev/null +++ b/pages/detail/detail.wxss @@ -0,0 +1,57 @@ +page { + box-sizing: border-box; + background-color: #fff; + padding: 0 20rpx; + padding-top: 20rpx; + padding-bottom: calc(env(safe-area-inset-bottom) + 106rpx); +} + +.title { + font-size: 34rpx; + list-style: square; + margin-bottom: 20rpx; + color: #363a44; +} + +.info { + display: flex; + font-size: 28rpx; + justify-content: space-between; + margin-bottom: 60rpx; + color: #b3b5b9; +} + +.info .viewcnt { + display: flex; + align-items: center; +} + +.info .viewcnt .t-icon { + margin-right: 12rpx; +} + + + +.content { + word-break: break-all; + line-height: 46rpx; + font-size: 26rpx; + color: #363a44; +} + +.img { + width: 100%; + margin: 20rpx auto; +} + +.video { + width: 100%; + margin: 20rpx auto; +} + +.source { + font-size: 24rpx; + color: #b3b5b9; + text-align: left; + margin-top: 40rpx; +} \ No newline at end of file diff --git a/pages/detail_admin/detail.js b/pages/detail_admin/detail.js new file mode 100644 index 0000000..0045231 --- /dev/null +++ b/pages/detail_admin/detail.js @@ -0,0 +1,66 @@ +// pages/detail_admin/detail.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad(options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady() { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow() { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide() { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload() { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh() { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom() { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage() { + + } +}) \ No newline at end of file diff --git a/pages/detail_admin/detail.wxml b/pages/detail_admin/detail.wxml new file mode 100644 index 0000000..1667bb2 --- /dev/null +++ b/pages/detail_admin/detail.wxml @@ -0,0 +1,2 @@ + +pages/detail_admin/detail.wxml \ No newline at end of file diff --git a/pages/faxianlist/faxianlist.js b/pages/faxianlist/faxianlist.js new file mode 100644 index 0000000..dc4c32d --- /dev/null +++ b/pages/faxianlist/faxianlist.js @@ -0,0 +1,107 @@ +import R from '../../utils/request'; +import C from '../../utils/constant'; +import * as F from '../../utils/func'; +Page({ + + data: { + cdnHost: C.cdnHost, + list: [], + page: 1, + status: '', + // money_flag: 'send', + listEndText: '', + }, + onShow() { + this.getTabBar().init(); + this.fetchList(1); + }, + onLoad(options) { + }, + goCreate(e) { + wx.navigateTo({ + url: `/pages/createpay/createpay` + }); + }, + fetchList(page) { + const { status } = this.data; + // money_flag + R.get('/index.php/api/v1/share_list', { page, status }).then(({ model }) => { + const list = []; + model.forEach(item => { + list.push({ + ...item, + price: F.formatePrice(item.price), + }); + }); + if (list.length == 0) { + this.setData({ listEndText: '没有更多了' }); + } else { + this.setData({ listEndText: '点击加载更多。。。' }); + } + if (page == 1) { + this.setData({ list,page }); + } else { + const list2 = this.data.list.concat(list); + this.setData({ list: list2,page }); + } + }); + // for (let i = 0; i < 20; i++) { + // list.push({ + // id: i, + // title: '自动热重载] 已开启代码文件保存后自动热重载自动热重载] 已开启代码文件保存后自动热重载', + // image: `${imageCdn}/swiper2.png`, + // createTime: '09-12 12:21', + // viewCnt: 1922 + i, + // }); + // } + // this.setData({ + // list + // }) + }, + loadMore() { + const { page, listEndText } = this.data; + if (listEndText == '点击加载更多。。。') { + this.fetchList(page + 1); + } + }, + onTabsChange(event) { + const v = event.detail.value; + this.data.status = v; + this.fetchList(1); + }, + // handleSwitchChange(e) { + // const { value } = e.detail; + // if (value) { + // this.data.money_flag = 'send'; + // } else { + // this.data.money_flag = ''; + // } + // this.fetchList(1); + // }, + onReachBottom() { + this.loadMore(); + }, + onPullDownRefresh() { + this.fetchList(1); + wx.stopPullDownRefresh(); + }, + editRemark(e) { + const { id, remark } = e.currentTarget.dataset.detail; + const that = this; + wx.showModal({ + title: '备注', + content: remark || '', + editable: true, + success(re) { + const remark2 = re.content || ''; + R.post('/index.php/api/v1/mark', { id, remark: remark2 }).then(() => { + that.data.list.find(o => o.id == id).remark = remark2; + that.setData({ + list: [...that.data.list], + }) + }) + } + }) + + } +}) \ No newline at end of file diff --git a/pages/faxianlist/faxianlist.json b/pages/faxianlist/faxianlist.json new file mode 100644 index 0000000..161bd58 --- /dev/null +++ b/pages/faxianlist/faxianlist.json @@ -0,0 +1,13 @@ +{ + "navigationBarTitleText": "我的分销", + "backgroundTextStyle": "light", + "usingComponents": { + "t-tabs": "tdesign-miniprogram/tabs/tabs", + "t-tab-panel": "tdesign-miniprogram/tab-panel/tab-panel", + "t-image": "tdesign-miniprogram/image/image", + "t-sticky": "tdesign-miniprogram/sticky/sticky", + "t-divider": "tdesign-miniprogram/divider/divider", + "t-icon": "tdesign-miniprogram/icon/icon", + "t-footer": "tdesign-miniprogram/footer/footer" + } +} \ No newline at end of file diff --git a/pages/faxianlist/faxianlist.wxml b/pages/faxianlist/faxianlist.wxml new file mode 100644 index 0000000..e9c36b2 --- /dev/null +++ b/pages/faxianlist/faxianlist.wxml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + 订单号: {{item.order_no || '-'}} 金额: {{item.price}} 元 + 购买信息: {{item.name}} {{item.phone}} + + + 备注: {{item.remark || '无'}} + + + + 支付时间: {{item.pay_time}} + 订单时间: {{item.create_time}} + {{item.buy_type}} + + + + + + + + + + + 创建 + 分销 + + \ No newline at end of file diff --git a/pages/faxianlist/faxianlist.wxss b/pages/faxianlist/faxianlist.wxss new file mode 100644 index 0000000..1715f76 --- /dev/null +++ b/pages/faxianlist/faxianlist.wxss @@ -0,0 +1,113 @@ +page { + padding: 0 20rpx; + background-color: rgb(245, 246, 247); +} + +.tabs { + display: flex; + justify-content: space-between; + background-color: rgb(245, 246, 247); +} + +.tabs .t-tabs { + width: 60%; + background: none !important; +} + +.tabs .t-tabs .t-tabs__wrapper { + background: none !important; +} + +.sw { + width: 240rpx; + display: flex; + align-items: center; + font-size: 32rpx; +} + +.sw .txt { + padding-left: 16rpx; +} + + +.list { + margin-top: 20rpx; + padding-bottom: 60rpx; +} + +.list .item { + border-radius: 16rpx; + background-color: #fff; + margin-bottom: 20rpx; + width: 710rpx; + padding-top: 20rpx; +} + +.list .item .item-main { + display: flex; + padding-left: 20rpx; +} + +.list .item .item-main .right { + flex: 1; + padding: 0 32rpx; + padding-bottom: 20rpx; +} + +.list .item .item-main .right .text { + padding-top: 16rpx; + font-size: 28rpx; + line-height: 46rpx; + margin-bottom: 20rpx; + color: #333; +} + +.list .item .item-main .right .info { + display: flex; + font-size: 24rpx; + justify-content: space-between; + color: #8f9197; +} + +.list .item .item-main .right .info .viewcnt { + display: flex; + align-items: center; + padding: 0 20rpx; +} + +.list .item .item-main .right .info .viewcnt.init { + color: blue; +} + +.list .item .item-main .right .info .viewcnt.resolve { + color: green; +} + +.list .item .item-main .right .info .viewcnt.reject { + color: gray; +} +.remark{ + display: flex; +} +.btn_cre { + position: fixed; + bottom: 220rpx; + right: 20rpx; + height: 120rpx; + width: 120rpx; + border-radius: 50%; + background-color: rgb(111, 172, 207); + color: #fff; + font-size: 26rpx; + z-index: 2; + padding-top: 26rpx; + box-sizing: border-box; +} + +.btn_cre view { + display: flex; + align-items: center; + justify-content: center; + flex-direction: row; + text-align: center; +} \ No newline at end of file diff --git a/pages/home/home.js b/pages/home/home.js new file mode 100644 index 0000000..ac6e151 --- /dev/null +++ b/pages/home/home.js @@ -0,0 +1,106 @@ +import R from '../../utils/request'; +import C from '../../utils/constant'; +Page({ + data: { + cdnHost: C.cdnHost, + loadFlag: false, + swiperList: [], + list: [], + }, + + onShow() { + this.getTabBar().init(); + // this.init(); + this.fetchBanner(); + }, + + onLoad() { + R.login().then(() => { + this.init(); + }) + }, + fetchBanner() { + R.get('/index.php/api/v1/banner_list', {}).then(({ model }) => { + const swiperList = []; + model.forEach(item => { + swiperList.push({ + ...item, + value: C.cdnHost + item.img, + ariaLabel: item.title, + id: item.id, + }); + }); + if (JSON.stringify(swiperList) != JSON.stringify(this.data.swiperList)) { + this.setData({ swiperList }); + } + }); + }, + init() { + if (this.data.loadFlag) return; + this.data.loadFlag = false; + this.fetchList(1); + this.fetchBanner(); + }, + fetchList(page) { + R.get('/index.php/api/v1/news_list', { page, pageSize: 5 }).then(({ model }) => { + const list = []; + model.forEach(item => { + list.push({ + ...item, + }); + }); + this.setData({ list }); + }); + }, + goDetail(e) { + const { id } = e.currentTarget.dataset; + wx.navigateTo({ + url: `/pages/detail/detail?id=${id}` + }); + }, + onSwiperTap(e) { + const { index } = e.detail; + this.data.swiperList.forEach((o, i) => { + if (i == index) { + console.log(o) + if(o.action_type == 'newsId'){ + wx.navigateTo({ + url: '/pages/detail/detail?id=' + o.action_item, + }); + } + if(o.action_type == 'url'){ + wx.navigateTo({ + url: '/pages/webview/webview?url=' + encodeURIComponent(o.action_item), + }); + } + if(o.action_type == 'path'){ + wx.navigateTo({ + url: o.action_item, + }); + } + } + }) + }, + goUrl(e) { + const { url } = e.currentTarget.dataset; + wx.navigateTo({ + url + }); + }, + goMore() { + wx.navigateTo({ + url: '/pages/news_list/home' + }); + }, + refresh() { + this.fetchList(1); + this.fetchBanner(); + wx.showToast({ icon: 'none', title: '刷新成功' }); + }, + onPullDownRefresh() { + this.init(); + wx.stopPullDownRefresh(); + }, + onShareAppMessage() { }, + onShareTimeline() { }, +}); diff --git a/pages/home/home.json b/pages/home/home.json new file mode 100644 index 0000000..edeed79 --- /dev/null +++ b/pages/home/home.json @@ -0,0 +1,12 @@ +{ + "navigationBarTitleText": "首页", + "backgroundTextStyle": "light", + "usingComponents": { + "t-swiper": "tdesign-miniprogram/swiper/swiper", + "t-swiper-nav": "tdesign-miniprogram/swiper-nav/swiper-nav", + "t-icon": "tdesign-miniprogram/icon/icon", + "t-image": "tdesign-miniprogram/image/image", + "t-divider": "tdesign-miniprogram/divider/divider" + }, + "enablePullDownRefresh": true +} \ No newline at end of file diff --git a/pages/home/home.less b/pages/home/home.less new file mode 100644 index 0000000..f0ae0f8 --- /dev/null +++ b/pages/home/home.less @@ -0,0 +1,101 @@ +page { + box-sizing: border-box; + background-color: linear-gradient(180deg, #f0f4fc, #fff); + padding: 0 20rpx; + padding-top: 10rpx; + padding-bottom: calc(env(safe-area-inset-bottom) + 106rpx); +} + +.title_bar { + display: flex; + align-items: center; + justify-content: space-between; + margin-top: 32rpx; +} + +.title_bar .title { + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + background-position: left center; + background-size: 100% 100%; + font-size: 32rpx; + color: rgb(53, 58, 71); + height: 34rpx; + display: flex; + align-items: center; + font-weight: bold; + + .t-icon { + margin-left: 10rpx; + } +} + + +.title_bar .btn { + color: #71737b; + font-size: 28rpx; + display: flex; + align-items: center; +} + +.title_bar .btn .t-icon { + margin-left: 10rpx; +} + +.list { + margin-top: 20rpx; +} + +.list .item .item-main { + display: flex; +} + +.list .item .item-main .right { + flex: 1; + padding-left: 32rpx; +} + +.list .item .item-main .right .text { + padding-top: 0rpx; + font-size: 28rpx; + line-height: 46rpx; + margin-bottom: 10rpx; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + overflow: hidden; + text-overflow: ellipsis; + color: #363a44; + +} + +.list .item .item-main .right .info { + display: flex; + font-size: 24rpx; + justify-content: space-between; + color: #71737b; +} + +.list .item .item-main .right .info .viewcnt { + display: flex; + align-items: center; +} + +.list .item .viewcnt .t-icon { + margin-right: 10rpx; +} + +.t-tab-bar { + border-top: 1px solid #eee; + position: relative; +} + +.activity { + display: flex; + justify-content: space-between; + padding: 20rpx 0; + border-bottom: 1px solid #eee; + + .t-image { + width: 100%; + } +} \ No newline at end of file diff --git a/pages/home/home.wxml b/pages/home/home.wxml new file mode 100644 index 0000000..52815cb --- /dev/null +++ b/pages/home/home.wxml @@ -0,0 +1,31 @@ + + + + + 公司动态 + + + + 查看全部 + + + + + + + + + {{item.title}} + + {{item.create_time}} + + + {{item.view_cnt}} + + + + + + + + \ No newline at end of file diff --git a/pages/home/home.wxss b/pages/home/home.wxss new file mode 100644 index 0000000..ca12594 --- /dev/null +++ b/pages/home/home.wxss @@ -0,0 +1,84 @@ +page { + box-sizing: border-box; + background-color: linear-gradient(180deg, #f0f4fc, #fff); + padding: 0 20rpx; + padding-top: 10rpx; + padding-bottom: calc(env(safe-area-inset-bottom) + 106rpx); +} +.title_bar { + display: flex; + align-items: center; + justify-content: space-between; + margin-top: 32rpx; +} +.title_bar .title { + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + background-position: left center; + background-size: 100% 100%; + font-size: 32rpx; + color: #353a47; + height: 34rpx; + display: flex; + align-items: center; + font-weight: bold; +} +.title_bar .title .t-icon { + margin-left: 10rpx; +} +.title_bar .btn { + color: #71737b; + font-size: 28rpx; + display: flex; + align-items: center; +} +.title_bar .btn .t-icon { + margin-left: 10rpx; +} +.list { + margin-top: 20rpx; +} +.list .item .item-main { + display: flex; +} +.list .item .item-main .right { + flex: 1; + padding-left: 32rpx; +} +.list .item .item-main .right .text { + padding-top: 0rpx; + font-size: 28rpx; + line-height: 46rpx; + margin-bottom: 10rpx; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + overflow: hidden; + text-overflow: ellipsis; + color: #363a44; +} +.list .item .item-main .right .info { + display: flex; + font-size: 24rpx; + justify-content: space-between; + color: #71737b; +} +.list .item .item-main .right .info .viewcnt { + display: flex; + align-items: center; +} +.list .item .viewcnt .t-icon { + margin-right: 10rpx; +} +.t-tab-bar { + border-top: 1px solid #eee; + position: relative; +} +.activity { + display: flex; + justify-content: space-between; + padding: 20rpx 0; + border-bottom: 1px solid #eee; +} +.activity .t-image { + width: 100%; +} diff --git a/pages/home/readme b/pages/home/readme new file mode 100644 index 0000000..fcf75d5 --- /dev/null +++ b/pages/home/readme @@ -0,0 +1,8 @@ +首页功能设定 +1. loading入场 +2. 下拉刷新 +3. 搜索栏 +4. 分类切换 +5. 商品列表 +6. 规格弹层 +7. 加载更多 \ No newline at end of file diff --git a/pages/news_admin_list/home.js b/pages/news_admin_list/home.js new file mode 100644 index 0000000..38b1370 --- /dev/null +++ b/pages/news_admin_list/home.js @@ -0,0 +1,66 @@ +// pages/news_admin_list/home.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad(options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady() { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow() { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide() { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload() { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh() { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom() { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage() { + + } +}) \ No newline at end of file diff --git a/pages/news_admin_list/home.wxml b/pages/news_admin_list/home.wxml new file mode 100644 index 0000000..f6cd162 --- /dev/null +++ b/pages/news_admin_list/home.wxml @@ -0,0 +1,2 @@ + +pages/news_admin_list/home.wxml \ No newline at end of file diff --git a/pages/news_list/home.js b/pages/news_list/home.js new file mode 100644 index 0000000..d3848f8 --- /dev/null +++ b/pages/news_list/home.js @@ -0,0 +1,63 @@ +import R from '../../utils/request'; +import C from '../../utils/constant'; +Page({ + data: { + cdnHost: C.cdnHost, + list: [], + page: 1, + listEndText: '', + }, + + onShow() { + this.getTabBar().init(); + }, + + onLoad() { + this.init(); + }, + init() { + this.fetchList(1); + }, + fetchList(page) { + R.get('/index.php/api/v1/news_list', { page }).then(({ model }) => { + const list = []; + model.forEach(item => { + list.push({ + ...item, + }); + }); + if (list.length == 0) { + this.setData({ listEndText: '没有更多了' }); + } else { + this.setData({ listEndText: '点击加载更多。。。' }); + } + if (page == 1) { + this.setData({ list ,page}); + } else { + const list2 = this.data.list.concat(list); + this.setData({ list: list2,page }); + } + }); + }, + loadMore() { + const { page, listEndText } = this.data; + if (listEndText == '点击加载更多。。。') { + this.fetchList(page + 1); + } + }, + goDetail(e) { + const { id } = e.currentTarget.dataset; + wx.navigateTo({ + url: `/pages/detail/detail?id=${id}` + }); + }, + refresh() { + this.fetchList(1); + wx.showToast({ icon: 'none', title: '刷新成功' }); + }, + // 下拉刷新 + onPullDownRefresh() { + this.init(); + wx.stopPullDownRefresh(); + }, +}); diff --git a/pages/news_list/home.json b/pages/news_list/home.json new file mode 100644 index 0000000..f42b6d5 --- /dev/null +++ b/pages/news_list/home.json @@ -0,0 +1,10 @@ +{ + "navigationBarTitleText": "发现", + "backgroundTextStyle": "light", + "usingComponents": { + "t-icon": "tdesign-miniprogram/icon/icon", + "t-image": "tdesign-miniprogram/image/image", + "t-divider": "tdesign-miniprogram/divider/divider", + "t-footer": "tdesign-miniprogram/footer/footer" + } +} \ No newline at end of file diff --git a/pages/news_list/home.less b/pages/news_list/home.less new file mode 100644 index 0000000..2f55659 --- /dev/null +++ b/pages/news_list/home.less @@ -0,0 +1,95 @@ +page { + box-sizing: border-box; + background-color: linear-gradient(180deg, #f0f4fc, #fff); + padding: 0 20rpx; + padding-top: 10rpx; + padding-bottom: calc(env(safe-area-inset-bottom) + 106rpx); +} + +.title_bar { + display: flex; + align-items: center; + justify-content: space-between; + margin-top: 32rpx; +} + +.title_bar .title { + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + // background: url('http://cdn.zhonganonline.top/newslist/static/title.png') no-repeat; + background-position: left center; + background-size: 100% 100%; + font-size: 32rpx; + height: 34rpx; + width: 132rpx; +} + + +.title_bar .btn { + color: #71737b; + font-size: 28rpx; + display: flex; + align-items: center; +} + +.title_bar .btn .t-icon { + margin-right: 10rpx; +} + +.list { + margin-top: 20rpx; +} + +.list .item .item-main { + display: flex; +} + +.list .item .item-main .right { + flex: 1; + padding-left: 32rpx; +} + +.list .item .item-main .right .text { + padding-top: 0rpx; + font-size: 28rpx; + line-height: 46rpx; + margin-bottom: 10rpx; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + overflow: hidden; + text-overflow: ellipsis; + color: #363a44; + +} + +.list .item .item-main .right .info { + display: flex; + font-size: 24rpx; + justify-content: space-between; + color: #71737b; +} + +.list .item .item-main .right .info .viewcnt { + display: flex; + align-items: center; +} + +.list .item .viewcnt .t-icon { + margin-right: 10rpx; +} + +.t-tab-bar { + border-top: 1px solid #eee; + position: relative; +} + +.activity { + display: flex; + justify-content: space-between; + padding: 20rpx 0; + border-bottom: 1px solid #eee; + + .t-image { + width: 100%; + } +} \ No newline at end of file diff --git a/pages/news_list/home.wxml b/pages/news_list/home.wxml new file mode 100644 index 0000000..5d68466 --- /dev/null +++ b/pages/news_list/home.wxml @@ -0,0 +1,28 @@ + + + 最新动态 + + + 刷新 + + + + + + + + {{item.title}} + + {{item.create_time}} + + + {{item.view_cnt}} + + + + + + + + + \ No newline at end of file diff --git a/pages/news_list/home.wxss b/pages/news_list/home.wxss new file mode 100644 index 0000000..47510fc --- /dev/null +++ b/pages/news_list/home.wxss @@ -0,0 +1,78 @@ +page { + box-sizing: border-box; + background-color: linear-gradient(180deg, #f0f4fc, #fff); + padding: 0 20rpx; + padding-top: 10rpx; + padding-bottom: calc(env(safe-area-inset-bottom) + 106rpx); +} +.title_bar { + display: flex; + align-items: center; + justify-content: space-between; + margin-top: 32rpx; +} +.title_bar .title { + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + background-position: left center; + background-size: 100% 100%; + font-size: 32rpx; + height: 34rpx; + width: 132rpx; +} +.title_bar .btn { + color: #71737b; + font-size: 28rpx; + display: flex; + align-items: center; +} +.title_bar .btn .t-icon { + margin-right: 10rpx; +} +.list { + margin-top: 20rpx; +} +.list .item .item-main { + display: flex; +} +.list .item .item-main .right { + flex: 1; + padding-left: 32rpx; +} +.list .item .item-main .right .text { + padding-top: 0rpx; + font-size: 28rpx; + line-height: 46rpx; + margin-bottom: 10rpx; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + overflow: hidden; + text-overflow: ellipsis; + color: #363a44; +} +.list .item .item-main .right .info { + display: flex; + font-size: 24rpx; + justify-content: space-between; + color: #71737b; +} +.list .item .item-main .right .info .viewcnt { + display: flex; + align-items: center; +} +.list .item .viewcnt .t-icon { + margin-right: 10rpx; +} +.t-tab-bar { + border-top: 1px solid #eee; + position: relative; +} +.activity { + display: flex; + justify-content: space-between; + padding: 20rpx 0; + border-bottom: 1px solid #eee; +} +.activity .t-image { + width: 100%; +} diff --git a/pages/news_list/readme b/pages/news_list/readme new file mode 100644 index 0000000..fcf75d5 --- /dev/null +++ b/pages/news_list/readme @@ -0,0 +1,8 @@ +首页功能设定 +1. loading入场 +2. 下拉刷新 +3. 搜索栏 +4. 分类切换 +5. 商品列表 +6. 规格弹层 +7. 加载更多 \ No newline at end of file diff --git a/pages/pay/pay.js b/pages/pay/pay.js new file mode 100644 index 0000000..c79582f --- /dev/null +++ b/pages/pay/pay.js @@ -0,0 +1,39 @@ +import R from '../../utils/request'; +import C from '../../utils/constant'; +import * as F from '../../utils/func'; +Page({ + data: { + + }, + onLoad(options) { + const { order_no, redirect_url } = options; + + R.post('/index.php/api/v1/pay_order_shop', { order_no }).then(({ model }) => { + wx.requestPayment({ + ...model, + success(res) { + wx.showToast({ + title: '支付成功', + icon: 'success', + duration: 2000, + success() { + wx.redirectTo({ + url: '/pages/shop/shop?path=user', + }); + } + }) + }, + fail(res) { + wx.showToast({ + title: '支付失败', + icon: 'none', + duration: 2000 + }) + wx.redirectTo({ + url: '/pages/shop/shop?path=user', + }); + } + }) + }) + }, +}) \ No newline at end of file diff --git a/pages/pay/pay.json b/pages/pay/pay.json new file mode 100644 index 0000000..37df5a9 --- /dev/null +++ b/pages/pay/pay.json @@ -0,0 +1,5 @@ +{ + "navigationBarTitleText": "支付", + "backgroundTextStyle": "light", + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/pay/pay.wxml b/pages/pay/pay.wxml new file mode 100644 index 0000000..fd8db04 --- /dev/null +++ b/pages/pay/pay.wxml @@ -0,0 +1 @@ +支付中... \ No newline at end of file diff --git a/pages/pay/pay.wxss b/pages/pay/pay.wxss new file mode 100644 index 0000000..8a92a43 --- /dev/null +++ b/pages/pay/pay.wxss @@ -0,0 +1,4 @@ +.tip { + text-align: center; + margin-top: 20px; +} \ No newline at end of file diff --git a/pages/paylist/paylist.js b/pages/paylist/paylist.js new file mode 100644 index 0000000..17849d3 --- /dev/null +++ b/pages/paylist/paylist.js @@ -0,0 +1,105 @@ +import R from '../../utils/request'; +import C from '../../utils/constant'; +import * as F from '../../utils/func'; +Page({ + + data: { + cdnHost: C.cdnHost, + list: [], + page: 1, + status: '', + // money_flag: 'send', + listEndText: '', + }, + onLoad(options) { + const {from} = options; + if(from == 'sharebuy') { + R.post('/index.php/api/v1/configs',{ks:['payed_tip','payed_vip_link']}).then(({model})=>{ + if(model.payed_tip && model.payed_vip_link) { + wx.showModal({ + title: '提示', + content: model.payed_tip, + complete: (res) => { + if (res.confirm) { + wx.navigateTo({ + url: '/pages/webview/webview?url=' + encodeURIComponent(model.payed_vip_link), + }) + } + } + }) + } + + }) + } + this.fetchList(1); + }, + goDetail(e) { + const { detail } = e.currentTarget.dataset; + if (!detail.phone && detail.status == 'payed') { + wx.navigateTo({ + url: `/pages/sharebuy/sharebuy?id=${detail.share_id}&orderNo=${detail.order_no}`, + }); + } + }, + fetchList(page) { + const { status } = this.data; + // money_flag + R.get('/index.php/api/v1/order_list', { page }).then(({ model }) => { + const list = []; + model.forEach(item => { + list.push({ + ...item, + price: F.formatePrice(item.price), + }); + }); + if (list.length == 0) { + this.setData({ listEndText: '没有更多了' }); + } else { + this.setData({ listEndText: '点击加载更多。。。' }); + } + if (page == 1) { + this.setData({ list,page }); + } else { + const list2 = this.data.list.concat(list); + this.setData({ list: list2,page }); + } + }); + // for (let i = 0; i < 20; i++) { + // list.push({ + // id: i, + // title: '自动热重载] 已开启代码文件保存后自动热重载自动热重载] 已开启代码文件保存后自动热重载', + // image: `${imageCdn}/swiper2.png`, + // createTime: '09-12 12:21', + // viewCnt: 1922 + i, + // }); + // } + // this.setData({ + // list + // }) + }, + loadMore() { + const { page, listEndText } = this.data; + if (listEndText == '点击加载更多。。。') { + this.fetchList(page + 1); + } + }, + onTabsChange(event) { + const v = event.detail.value; + this.data.status = v; + this.fetchList(1); + }, + // handleSwitchChange(e) { + // const { value } = e.detail; + // if (value) { + // this.data.money_flag = 'send'; + // } else { + // this.data.money_flag = ''; + // } + // this.fetchList(1); + // }, + onReachBottom() { + this.loadMore(); + }, + onShareAppMessage() { + } +}) \ No newline at end of file diff --git a/pages/paylist/paylist.json b/pages/paylist/paylist.json new file mode 100644 index 0000000..9d00d9d --- /dev/null +++ b/pages/paylist/paylist.json @@ -0,0 +1,12 @@ +{ + "navigationBarTitleText": "我的订单", + "backgroundTextStyle": "light", + "usingComponents": { + "t-tabs": "tdesign-miniprogram/tabs/tabs", + "t-tab-panel": "tdesign-miniprogram/tab-panel/tab-panel", + "t-image": "tdesign-miniprogram/image/image", + "t-sticky": "tdesign-miniprogram/sticky/sticky", + "t-divider": "tdesign-miniprogram/divider/divider", + "t-footer": "tdesign-miniprogram/footer/footer" + } +} \ No newline at end of file diff --git a/pages/paylist/paylist.wxml b/pages/paylist/paylist.wxml new file mode 100644 index 0000000..df03ff2 --- /dev/null +++ b/pages/paylist/paylist.wxml @@ -0,0 +1,31 @@ + + + + + + + 订单号: {{item.order_no || '-'}} + {{item.price}}元 + + + {{item.buy_type}} + 补充信息{{' >'}} + + + 信息: {{item.name || '暂无'}} {{item.phone}} + {{item.buy_type}} + + + 支付时间: {{item.pay_time}} + 订单时间: {{item.create_time}} + + + 已支付 + 待支付 + + + + + + + \ No newline at end of file diff --git a/pages/paylist/paylist.wxss b/pages/paylist/paylist.wxss new file mode 100644 index 0000000..1197a3b --- /dev/null +++ b/pages/paylist/paylist.wxss @@ -0,0 +1,76 @@ +page { + padding: 0 20rpx; + background-color: rgb(245, 246, 247); +} +.sw { + width: 240rpx; + display: flex; + align-items: center; + font-size: 32rpx; +} + +.sw .txt { + padding-left: 16rpx; +} + + +.list { + margin-top: 20rpx; + padding-bottom: 60rpx; +} + +.list .item { + border-radius: 16rpx; + background-color: #fff; + margin-bottom: 20rpx; + width: 710rpx; + padding-top: 20rpx; +} + +.list .item .item-main { + display: flex; + padding-left: 20rpx; +} + +.list .item .item-main .right { + flex: 1; + padding: 0 32rpx; + padding-bottom: 20rpx; +} + +.list .item .item-main .right .text { + display: flex; + font-size: 28rpx; + justify-content: space-between; + color: #333; +} + +.list .item .item-main .right .info { + display: flex; + font-size: 24rpx; + justify-content: space-between; + color: #8f9197; + line-height: 36rpx; +} + +.list .item .item-main .right .info .viewcnt { + display: flex; + align-items: center; + padding: 0 20rpx; +} + +.list .item .item-main .right .info .viewcnt.init { + color: blue; +} + +.list .item .item-main .right .info .viewcnt.resolve { + color: green; +} + +.list .item .item-main .right .info .viewcnt.reject { + color: gray; +} + +.list .item .h20 { + height: 20rpx; +} diff --git a/pages/sharebuy/sharebuy.js b/pages/sharebuy/sharebuy.js new file mode 100644 index 0000000..ad9d043 --- /dev/null +++ b/pages/sharebuy/sharebuy.js @@ -0,0 +1,141 @@ +import C from '../../utils/constant'; +import * as F from '../../utils/func'; +import R from '../../utils/request'; +Page({ + data: { + expireDate: '', + price: '', + shareId: '', + isPay: false, + orderNo: '', + phone: '', + username: '', + tip_before_pay: '', + tip_after_pay: '', + buy_type: '', + }, + onLoad(options) { + const { id, orderNo } = options; + if (orderNo) { + this.setData({ + isPay: true, + orderNo, + }) + this.fetchOrder(orderNo); + } else { + R.get('/index.php/api/v1/get_share', { id }).then(({ model }) => { + this.setData({ + shareId: id, + price: F.formatePrice(model.price), + expireDate: model.expire_time, + tip_before_pay: model.tip_before_pay || '', + tip_after_pay: model.tip_after_pay || '', + buy_type: model.buy_type, + }); + }).catch((e)=>{ + console.log('xxx',e); + }) + R.get('/index.php/api/v1/view_share', { id }); + } + }, + refresh() { + if (this.data.orderNo) { + this.fetchOrder(this.data.orderNo); + } + }, + fetchOrder(orderNo) { + const that = this; + return R.get('/index.php/api/v1/fetch_order_pay', { order_no: orderNo }).then(({ model }) => { + console.log('payed', model); + if (model.status === 'payed') { + clearInterval(that.data.timer); + wx.hideLoading(); + this.setData({ + isPay: true, + orderNo, + price: F.formatePrice(model.price), + buy_type: model.buy_type, + }); + } + }); + }, + checkOrderStatus(orderNo) { + wx.showLoading({ + title: '确认支付中...', + }) + this.data.timer = setInterval(() => { + this.fetchOrder(orderNo).catch(() => { + clearInterval(this.data.timer); + }); + }, 1000); + }, + goPay() { + const that = this; + if (this.data.shareId) { + R.post('/index.php/api/v1/make_order', { share_id: this.data.shareId }).then(({ model: { order_no } }) => { + that.data.orderNo = order_no; + R.post('/index.php/api/v1/pay_order', { order_no }).then(({ model }) => { + wx.requestPayment({ + ...model, + success(res) { + wx.showToast({ + title: '支付成功', + icon: 'success', + duration: 2000, + success() { + that.checkOrderStatus(order_no); + // this.setData({ + // isPay: true, + // }) + } + }) + }, + fail(res) { + wx.showToast({ + title: '您已取消支付', + icon: 'none', + duration: 2000 + }) + // wx.redirectTo({ + // url: '/pages/shop/shop?path=user', + // }); + } + }) + }) + }) + } + }, + onShareAppMessage() { + + }, + validate() { + const { username, phone, orderNo, } = this.data; + if (!username) { + wx.showToast({ title: '请输入姓名', icon: 'none' }); + return false; + } + if (!/^1\d{10}$/.test(phone)) { + wx.showToast({ title: '请输入正确的手机号', icon: 'none' }); + return false; + } + return true; + }, + submit() { + if (!this.validate()) return; + const { + username, phone, orderNo, + } = this.data + R.post('/index.php/api/v1/mark_order_info', { name: username, phone, order_no: orderNo, }).then(({ model }) => { + wx.showToast({ + title: '提交成功', + icon: 'success', + duration: 2000, + success() { + wx.redirectTo({ + url: '/pages/paylist/paylist?from=sharebuy', + }) + } + }); + }); + }, +}) \ No newline at end of file diff --git a/pages/sharebuy/sharebuy.json b/pages/sharebuy/sharebuy.json new file mode 100644 index 0000000..dc8fabd --- /dev/null +++ b/pages/sharebuy/sharebuy.json @@ -0,0 +1,9 @@ +{ + "navigationBarTitleText": "支付", + "backgroundTextStyle": "light", + "usingComponents": { + "t-cell": "tdesign-miniprogram/cell/cell", + "t-button": "tdesign-miniprogram/button/button", + "t-input": "tdesign-miniprogram/input/input" + } +} \ No newline at end of file diff --git a/pages/sharebuy/sharebuy.less b/pages/sharebuy/sharebuy.less new file mode 100644 index 0000000..d180414 --- /dev/null +++ b/pages/sharebuy/sharebuy.less @@ -0,0 +1,57 @@ +page { + box-sizing: border-box; + background-color: linear-gradient(180deg, #f0f4fc, #fff); + padding: 0 20rpx; + padding-top: 10rpx; + padding-bottom: calc(env(safe-area-inset-bottom) + 106rpx); +} + +.logo { + height: 180rpx; + width: 180rpx; + margin: 0 auto; + background-image: url('http://cdn.zhonganonline.top/liiistem/static/liii_icon.png'); + background-position: center; + background-repeat: no-repeat; + background-size: cover; +} + +.form { + background: #fff; + border-radius: 10rpx; + overflow: hidden; +} + +.footer { + margin-top: 40rpx; + padding: 0 20rpx; +} + +.card { + margin: 20rpx 0; + padding: 0 20rpx; + + .line { + font-size: 36rpx; + line-height: 60rpx; + } + + +} + +.ma { + height: 20rpx; +} + +.desc { + color: #666; + font-size: 28rpx; + margin-top: 20rpx; + line-height: 34rpx; +} + +.refresh{ + text-align: center; + margin-top: 20rpx; + color: #999; +} \ No newline at end of file diff --git a/pages/sharebuy/sharebuy.wxml b/pages/sharebuy/sharebuy.wxml new file mode 100644 index 0000000..4a7d0a4 --- /dev/null +++ b/pages/sharebuy/sharebuy.wxml @@ -0,0 +1,37 @@ + + + + + + + + 立即付款 + 已支付? 手动刷新 + + + + + + + + + + + + + + + + + + + + 提交 + + + + + + + \ No newline at end of file diff --git a/pages/sharebuy/sharebuy.wxss b/pages/sharebuy/sharebuy.wxss new file mode 100644 index 0000000..d2e4ad3 --- /dev/null +++ b/pages/sharebuy/sharebuy.wxss @@ -0,0 +1,48 @@ +page { + box-sizing: border-box; + background-color: linear-gradient(180deg, #f0f4fc, #fff); + padding: 0 20rpx; + padding-top: 10rpx; + padding-bottom: calc(env(safe-area-inset-bottom) + 106rpx); +} +.logo { + height: 180rpx; + width: 180rpx; + margin: 0 auto; + background-image: url('http://cdn.zhonganonline.top/liiistem/static/liii_icon.png'); + background-position: center; + background-repeat: no-repeat; + background-size: cover; +} +.form { + background: #fff; + border-radius: 10rpx; + overflow: hidden; +} +.footer { + margin-top: 40rpx; + padding: 0 20rpx; +} +.card { + margin: 20rpx 0; + padding: 0 20rpx; +} +.card .line { + font-size: 36rpx; + line-height: 60rpx; +} +.ma { + height: 20rpx; +} +.desc { + color: #666; + font-size: 28rpx; + margin-top: 20rpx; + line-height: 34rpx; +} + +.refresh{ + text-align: center; + margin-top: 20rpx; + color: #999; +} \ No newline at end of file diff --git a/pages/sharelist/sharelist.js b/pages/sharelist/sharelist.js new file mode 100644 index 0000000..4267eb5 --- /dev/null +++ b/pages/sharelist/sharelist.js @@ -0,0 +1,77 @@ +import R from '../../utils/request'; +import C from '../../utils/constant'; +import * as F from '../../utils/func'; +Page({ + + data: { + cdnHost: C.cdnHost, + list: [], + page: 1, + status: '', + // money_flag: 'send', + listEndText: '', + }, + onLoad(options) { + this.fetchList(1); + }, + goDel(e) { + const {detail,index} =e.currentTarget.dataset; + if(detail.deleted == 1) return; + const {id}=detail; + wx.showModal({ + title: '提示', + content: '置为失效后无法恢复,确认继续吗?', + complete: (res) => { + if (res.cancel) { + + } + + if (res.confirm) { + R.post('/index.php/api/v1/del_share',{id}).then(()=>{ + const {list} = this.data; + this.setData({ + [`list[${index}]`] : { + ...list[index], + deleted:1, + }, + }); + }) + } + } + }) + }, + fetchList(page) { + const { status } = this.data; + // money_flag + R.get('/index.php/api/v1/share_link_list', { page }).then(({ model }) => { + const list = []; + model.forEach(item => { + list.push({ + ...item, + price: F.formatePrice(item.price), + expire_time: item.expire_time.split(' ')[0], + }); + }); + if (list.length == 0) { + this.setData({ listEndText: '没有更多了' }); + } else { + this.setData({ listEndText: '点击加载更多。。。' }); + } + if (page == 1) { + this.setData({ list,page }); + } else { + const list2 = this.data.list.concat(list); + this.setData({ list: list2 ,page}); + } + }); + }, + loadMore() { + const { page, listEndText } = this.data; + if (listEndText == '点击加载更多。。。') { + this.fetchList(page + 1); + } + }, + onReachBottom() { + this.loadMore(); + }, +}) \ No newline at end of file diff --git a/pages/sharelist/sharelist.json b/pages/sharelist/sharelist.json new file mode 100644 index 0000000..223d04a --- /dev/null +++ b/pages/sharelist/sharelist.json @@ -0,0 +1,12 @@ +{ + "navigationBarTitleText": "进行中的分销", + "backgroundTextStyle": "light", + "usingComponents": { + "t-tabs": "tdesign-miniprogram/tabs/tabs", + "t-tab-panel": "tdesign-miniprogram/tab-panel/tab-panel", + "t-image": "tdesign-miniprogram/image/image", + "t-sticky": "tdesign-miniprogram/sticky/sticky", + "t-divider": "tdesign-miniprogram/divider/divider", + "t-footer": "tdesign-miniprogram/footer/footer" + } +} \ No newline at end of file diff --git a/pages/sharelist/sharelist.wxml b/pages/sharelist/sharelist.wxml new file mode 100644 index 0000000..9f812c8 --- /dev/null +++ b/pages/sharelist/sharelist.wxml @@ -0,0 +1,23 @@ + + + + + + + {{item.buy_type || '-'}} + {{item.price}}元 + + + + 置为失效 + + + 创建: {{item.create_time}} + 截止: {{item.expire_time}} + + + + + + + \ No newline at end of file diff --git a/pages/sharelist/sharelist.wxss b/pages/sharelist/sharelist.wxss new file mode 100644 index 0000000..1197a3b --- /dev/null +++ b/pages/sharelist/sharelist.wxss @@ -0,0 +1,76 @@ +page { + padding: 0 20rpx; + background-color: rgb(245, 246, 247); +} +.sw { + width: 240rpx; + display: flex; + align-items: center; + font-size: 32rpx; +} + +.sw .txt { + padding-left: 16rpx; +} + + +.list { + margin-top: 20rpx; + padding-bottom: 60rpx; +} + +.list .item { + border-radius: 16rpx; + background-color: #fff; + margin-bottom: 20rpx; + width: 710rpx; + padding-top: 20rpx; +} + +.list .item .item-main { + display: flex; + padding-left: 20rpx; +} + +.list .item .item-main .right { + flex: 1; + padding: 0 32rpx; + padding-bottom: 20rpx; +} + +.list .item .item-main .right .text { + display: flex; + font-size: 28rpx; + justify-content: space-between; + color: #333; +} + +.list .item .item-main .right .info { + display: flex; + font-size: 24rpx; + justify-content: space-between; + color: #8f9197; + line-height: 36rpx; +} + +.list .item .item-main .right .info .viewcnt { + display: flex; + align-items: center; + padding: 0 20rpx; +} + +.list .item .item-main .right .info .viewcnt.init { + color: blue; +} + +.list .item .item-main .right .info .viewcnt.resolve { + color: green; +} + +.list .item .item-main .right .info .viewcnt.reject { + color: gray; +} + +.list .item .h20 { + height: 20rpx; +} diff --git a/pages/shop/shop.js b/pages/shop/shop.js new file mode 100644 index 0000000..c85dc3e --- /dev/null +++ b/pages/shop/shop.js @@ -0,0 +1,66 @@ +// pages/shop/shop.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad(options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady() { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow() { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide() { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload() { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh() { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom() { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage() { + + } +}) \ No newline at end of file diff --git a/pages/shop/shop.wxml b/pages/shop/shop.wxml new file mode 100644 index 0000000..c4246cb --- /dev/null +++ b/pages/shop/shop.wxml @@ -0,0 +1,2 @@ + +pages/shop/shop.wxml \ No newline at end of file diff --git a/pages/takephoto/takephoto.js b/pages/takephoto/takephoto.js new file mode 100644 index 0000000..40675e7 --- /dev/null +++ b/pages/takephoto/takephoto.js @@ -0,0 +1,405 @@ +import R from '../../utils/request'; +import C from '../../utils/constant'; +Page({ + data: { + cdnHost: C.cdnHost, + cdnHost: C.cdnHost, + title: '', + tel: '', + content: '', + shortAddress: '', + address: '', + video: '', + position: { + longitude: 0, + latitude: 0, + }, + ds: { + list: [], + refStatusNum: { finished: 0, failed: 0, process: 0 }, + }, + ts: { + refImgDescs: {}, + refImgKeywords: {}, + fileUploadList: [], + fileUploadList2: [], + isUploading: false, + timer: [], + }, + stop: false, + gridConfig: { + column: 4, + width: 160, + height: 160, + }, + config: { + count: 1, + }, + phoneError: false, + // + videoFileList: [], + }, + onLoad(options) { + const that = this; + R.get('/index.php/api/v1/my', {}).then(({ model }) => { + this.setData({ tel: model.phone }); + }); + wx.getFuzzyLocation({ + type: 'wgs84', + success(res) { + const longitude = res.longitude + const latitude = res.latitude + that.setData({ + position: { + longitude, + latitude, + }, + }); + R.get('/index.php/api/v1/gps', { lat: latitude, lon: longitude }).then(({ model }) => { + that.setData({ shortAddress: model.short_ad, address: model.full_ad }); + }); + } + }) + }, + onUnload() { + this.data.stop = true; + }, + onShareAppMessage() { + }, + choosePoi() { + const that = this; + wx.chooseLocation({ + success({ latitude, longitude, name, address }) { + that.setData({ + position: { + latitude, + longitude, + }, + shortAddress: name, + address, + }); + } + }) + }, + // + onPhoneInput(e) { + const { phoneError } = this.data; + const isPhoneNumber = /^[1][3,4,5,7,8,9][0-9]{9}$/.test(e.detail.value); + if (phoneError === isPhoneNumber) { + this.setData({ + phoneError: !isPhoneNumber, + }); + } + }, + onSubmit() { + console.log('this.stat', this.data); + const { title, tel, shortAddress, address, position, ds, content, videoFileList } = this.data; + if (ds.refStatusNum.failed > 0) { + wx.showToast({ + title: '请处理上传失败的图片', + icon: 'none', + }); + return; + } + if (ds.refStatusNum.process > 0) { + wx.showToast({ + title: '请等待图片上传完成', + icon: 'none', + }); + return; + } + // 每个属性都判空,并且给出toast提示 + if (!tel) { + wx.showToast({ + title: '请输入手机号', + icon: 'none', + }); + return; + } + if (!title) { + wx.showToast({ + title: '请输入标题', + icon: 'none', + }); + return; + } + if (!content) { + wx.showToast({ + title: '请输入您的发件信息', + icon: 'none', + }); + return; + } + if (!shortAddress) { + wx.showToast({ + title: '请选择位置', + icon: 'none', + }); + return; + } + if (ds.list.length === 0) { + wx.showToast({ + title: '请上传图片', + icon: 'none', + }); + return; + } + // 提交数据 + R.post('/index.php/api/v1/submit', { + title, + tel, + shortAddress, + address, + content, + longitude: position.longitude, + latitude: position.latitude, + imgs: ds.list.map((o) => o.path), + video: videoFileList && videoFileList.length > 0 ? videoFileList[0].path : undefined, + }).then(({ model }) => { + wx.showToast({ + title: '提交成功,感谢您的反馈', + icon: 'success', + }); + setTimeout(() => { + wx.navigateBack(); + }, 1000); + }); + }, + goBack() { + wx.navigateBack(); + }, + // + callStatusNum() { + const { ds } = this.data; + const s = { finished: 0, failed: 0, process: 0 }; + ds.list.forEach((o) => { + if (o.failed) s.failed++; + else if (o.finished) s.finished++; + else s.process++; + }); + this.setData({ + 'ds.refStatusNum': s, + }); + }, + imgHandleSuccess(e) { + console.log('imgHandleSuccess', e.detail); + // const { files } = e.detail; + // this.setData({ + // originFiles: files, + // }); + this.httpRequest(); + }, + imgHandleRemove(e) { + const { index } = e.detail; + console.log('imgHandleRemove', e.detail); + const { ds } = this.data; + ds.list.splice(index, 1); + this.setData({ + 'ds.list': ds.list, + }); + }, + imgHandleClick(e) { + console.log(e.detail.file); + }, + beforUpload(e) { + const { files } = e.detail; + console.log('beforUpload', files); + const { ts } = this.data; + const { fileUploadList, fileUploadList2 } = ts; + files.map((file) => { + fileUploadList.push(file); + fileUploadList2.push(file); + }) + this.setData({ + 'ts.fileUploadList': fileUploadList, + 'ts.fileUploadList2': fileUploadList2, + }); + }, + startPreview() { + console.log('startPreview'); + if (this.data.stop) return; + const { ts, ds } = this.data; + const { fileUploadList2 } = ts; + if (fileUploadList2.length > 0) { + const file = fileUploadList2.shift(); + ds.list.push({ + src: file.url, + url: file.url, + uid: file.name, + name: file.name, + percent: 0, + failed: false, + status: 'loading', + }) + this.setData({ + 'ts.fileUploadList2': fileUploadList2, + 'ds.list': ds.list, + }); + setTimeout(() => { + this.startPreview(); + }, 0); + } else { + setTimeout(() => { + this.startPreview(); + }, 2000); + } + }, + httpRequest(e) { + if (this.data.stop) return; + const { ts } = this.data; + if (ts.isUploading) return; + ts.isUploading = true; + console.log('httpRequest'); + // 循环检测 是否有文件可以上传 + setTimeout(() => { + this.uploadHandle(); + this.startPreview(); + }, 0); + }, + uploadHandle() { + console.log('uploadHandle'); + if (this.data.stop) return; + this.callStatusNum(); + const { ts, ds } = this.data; + const { fileUploadList } = ts; + if (fileUploadList.length > 0) { + console.log('fileUploadList', fileUploadList); + const file = fileUploadList.shift(); + // formData.append('imageData', file); + R.upload({ a: 1 }, 'img_file', file.url).catch((e) => e).then((response) => { + // console.log('response-response333', response); + ts.isUploading = false; + try { + response.data = JSON.parse(response.data); + } catch (error) { + response.data = null; + } + // console.log('asdfasd-response', response.data); + if (response.data && response.data.code == -1000) { + wx.showToast({ + title: '登录超时,请重新登录', + icon: 'none', + }); + setTimeout(() => { + wx.navigateTo({ url: '/pages/home/home' }); + }, 500) + return; + } + else if (response.data && response.data.success) { + console.log('asdfasd-response2222', response.data); + const { data: { model: { path } } } = response; + this.setData({ + 'ds.list': ds.list.map((o) => { + if (file.name == o.uid) { + return { ...o, path, finished: true, percent: 100, status: 'done' }; + } + return { ...o }; + }) + }); + // this.setData({ + // [`ds.list[${idx}].url`]: C.cdnHost + path, + // }); + // R.getImg(4, imageId).then((path) => { + // const tlist = this.data.ds.list; + // let idx = 0; + // // console.log('path', path); + // tlist.forEach((c, i) => { + // if (c.imageId == imageId) { + // idx = i; + // } + // }); + // if (idx) { + // this.setData({ + // [`ds.list[${idx}].url`]: path, + // }); + // } + // }) + // wx.showToast({ + // title: '图片:' + file.name + '已暂存', + // icon: 'success', + // }); + // this.saveTmpData(); + } else { + console.log(response, file.name); + let errorMsg = '上传失败,请移除后重试'; + // if (response.data && response.data.status == 529) { + // errorMsg = '其他图集中已存在,请移除'; + // } + this.setData({ + 'ds.list': ds.list.map((o) => { + if (file.name == o.uid) { + return { ...o, failed: errorMsg, status: 'failed' }; + } + return { ...o }; + }), + }); + wx.showToast({ + title: file.name + ',' + errorMsg, + icon: 'error', + }); + // this.saveTmpData(); + } + setTimeout(() => { + this.uploadHandle(); + }, 0); + }); + } else { + // setTimeout(() => { + // this.uploadHandle(); + // }, 2000); + } + }, + //video + handleVideoAdd(e) { + const { files } = e.detail; + files.forEach(file => this.uploadVideoFile(file)) + }, + uploadVideoFile(file) { + + wx.getVideoInfo({ src: file.url }).then((res) => { + if (res.duration > 180) { + wx.showToast({ + title: '视频时长不能超过3分钟', + icon: 'none', + }); + return; + } + + // + const { videoFileList } = this.data; + + this.setData({ + videoFileList: [...videoFileList, { ...file, path: '', status: 'loading' }], + }); + const { length } = videoFileList; + R.upload({ a: 2 }, 'video_file', file.url, (res) => { + this.setData({ + [`videoFileList[${length}].percent`]: res.progress, + }); + }).catch((e) => e).then((response) => { + try { + response.data = JSON.parse(response.data); + } catch (error) { + response.data = null; + } + if (response.data && response.data.success) { + const { data: { model: { path } } } = response; + console.log('asdfasd-response2222', response.data, this.data.videoFileList, length); + this.setData({ + [`videoFileList[${length}].status`]: 'done', + [`videoFileList[${length}].path`]: path, + }); + } + }); + }); + }, + handleVideoRemove(e) { + const { index } = e.detail; + const { videoFileList } = this.data; + + videoFileList.splice(index, 1); + this.setData({ + videoFileList, + }); + }, +}) \ No newline at end of file diff --git a/pages/takephoto/takephoto.json b/pages/takephoto/takephoto.json new file mode 100644 index 0000000..9163b8e --- /dev/null +++ b/pages/takephoto/takephoto.json @@ -0,0 +1,14 @@ +{ + "navigationBarTitleText": "有发现", + "backgroundTextStyle": "light", + "usingComponents": { + "t-image": "tdesign-miniprogram/image/image", + "t-input": "tdesign-miniprogram/input/input", + "t-cell": "tdesign-miniprogram/cell/cell", + "t-icon": "tdesign-miniprogram/icon/icon", + "t-notice-bar": "tdesign-miniprogram/notice-bar/notice-bar", + "t-upload": "tdesign-miniprogram/upload/upload", + "t-button": "tdesign-miniprogram/button/button", + "t-textarea": "tdesign-miniprogram/textarea/textarea" + } +} \ No newline at end of file diff --git a/pages/takephoto/takephoto.wxml b/pages/takephoto/takephoto.wxml new file mode 100644 index 0000000..e317174 --- /dev/null +++ b/pages/takephoto/takephoto.wxml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + {{shortAddress}} + + + 修正位置 + + + + + + + 确认发布 + 取消 + + \ No newline at end of file diff --git a/pages/takephoto/takephoto.wxss b/pages/takephoto/takephoto.wxss new file mode 100644 index 0000000..51785dc --- /dev/null +++ b/pages/takephoto/takephoto.wxss @@ -0,0 +1,93 @@ +page { + background-color: rgb(245, 246, 247); +} + +.img { + font-size: 12rpx; + width: 750rpx; + margin: 0 auto; + height: 530rpx; + display: block; +} + +.form { + margin: 0 20rpx; + border-radius: 4px; + background-color: #fff; + margin-top: -100rpx; + border-radius: 4px; +} + +.form .t-input__label { + position: relative; +} + +.form .t-input__label::after { + display: block; + content: '*'; + color: #f00; + position: absolute; + font-size: 40rpx; + right: -30rpx; + top: 0; +} + +.form .photos .t-image { + margin-left: 20rpx; + margin-bottom: 20rpx; +} + +.t-textarea__wrapper { + background-color: rgb(245, 246, 247); + border: 16rpx; +} + +.t-textarea__wrapper .t-textarea__wrapper-inner { + padding: 16rpx; + border: 16rpx; +} + + + +.local_bar { + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 40rpx; + border-bottom: 10px solid #fff; +} + +.local_bar .t-icon { + margin-right: 10rpx; +} + +.local_bar .local { + display: flex; + font-size: 24rpx; + align-items: center; + color: #333; +} + +.local_bar .btn { + display: flex; + font-size: 24rpx; + align-items: center; + color: blue; +} + +.t-notice-bar { + background: none !important; +} + +.btns { + padding: 0 40rpx; + padding-bottom: 90rpx; +} + +.btns .t-button { + margin-bottom: 20rpx; +} + +.t-upload .t-grid__content .t-grid-item { + width: auto !important; +} \ No newline at end of file diff --git a/pages/test/test.js b/pages/test/test.js new file mode 100644 index 0000000..7418ae9 --- /dev/null +++ b/pages/test/test.js @@ -0,0 +1,66 @@ +// pages/test/test.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad(options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady() { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow() { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide() { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload() { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh() { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom() { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage() { + + } +}) \ No newline at end of file diff --git a/pages/test/test.wxml b/pages/test/test.wxml new file mode 100644 index 0000000..42a34de --- /dev/null +++ b/pages/test/test.wxml @@ -0,0 +1,2 @@ + +pages/test/test.wxml \ No newline at end of file diff --git a/pages/usercenter/components/user-center-card/index.js b/pages/usercenter/components/user-center-card/index.js new file mode 100644 index 0000000..47593c4 --- /dev/null +++ b/pages/usercenter/components/user-center-card/index.js @@ -0,0 +1,35 @@ +const AuthStepType = { + ONE: 1, + TWO: 2, + THREE: 3, +}; + +Component({ + options: { + multipleSlots: true, + }, + properties: { + currAuthStep: { + type: Number, + value: AuthStepType.ONE, + }, + userInfo: { + type: Object, + value: {}, + }, + isNeedGetUserInfo: { + type: Boolean, + value: false, + }, + }, + data: { + defaultAvatarUrl: + 'https://cdn-we-retail.ym.tencent.com/miniapp/usercenter/icon-user-center-avatar@2x.png', + AuthStepType, + }, + methods: { + gotoUserEditPage() { + this.triggerEvent('gotoUserEditPage'); + }, + }, +}); diff --git a/pages/usercenter/components/user-center-card/index.json b/pages/usercenter/components/user-center-card/index.json new file mode 100644 index 0000000..e169f6f --- /dev/null +++ b/pages/usercenter/components/user-center-card/index.json @@ -0,0 +1,7 @@ +{ + "component": true, + "usingComponents": { + "t-icon": "tdesign-miniprogram/icon/icon", + "t-avatar": "tdesign-miniprogram/avatar/avatar" + } +} \ No newline at end of file diff --git a/pages/usercenter/components/user-center-card/index.wxml b/pages/usercenter/components/user-center-card/index.wxml new file mode 100644 index 0000000..42dd0a5 --- /dev/null +++ b/pages/usercenter/components/user-center-card/index.wxml @@ -0,0 +1,36 @@ + + + + + + {{'请登录'}} + + + + + + + + {{userInfo.nickName || '微信用户'}} + + + + + + + + + + + + + + {{userInfo.nickName || '微信用户'}} + + + diff --git a/pages/usercenter/components/user-center-card/index.wxss b/pages/usercenter/components/user-center-card/index.wxss new file mode 100644 index 0000000..f081f5f --- /dev/null +++ b/pages/usercenter/components/user-center-card/index.wxss @@ -0,0 +1,57 @@ +.user-center-card { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 480rpx; + background-image: url('https://cdn-we-retail.ym.tencent.com/miniapp/template/user-center-bg-v1.png'); + background-size: cover; + background-repeat: no-repeat; + padding: 0 24rpx; +} +.user-center-card__header { + margin-top: 192rpx; + margin-bottom: 48rpx; + height: 96rpx; + line-height: 48rpx; + display: flex; + justify-content: flex-start; + align-items: center; + color: #333; + position: relative; +} +.user-center-card__header__avatar { + width: 96rpx; + height: 96rpx; + border-radius: 48rpx; + overflow: hidden; +} + +.user-center-card__header__name .name{ + font-size: 36rpx; + line-height: 48rpx; + color: #333; + font-weight: bold; + margin-left: 24rpx; + margin-right: 16rpx; +} +.user-center-card__header__name .score{ + font-size: 22rpx; + line-height: 38rpx; + color: #333; + margin-left: 24rpx; + margin-right: 16rpx; + display: flex; + align-items: center; +} +.user-center-card__header__transparent { + position: absolute; + right: 0; + top: 0; + background-color: transparent; + height: 100%; + width: 30%; +} +.user-center-card__icon { + line-height: 96rpx; +} diff --git a/pages/usercenter/index.js b/pages/usercenter/index.js new file mode 100644 index 0000000..bcbfed9 --- /dev/null +++ b/pages/usercenter/index.js @@ -0,0 +1,79 @@ +import R from '../../utils/request'; +import C from '../../utils/constant'; +import * as F from '../../utils/func'; + +Page({ + data: { + cdnHost: C.cdnHost, + phone: '', + name: '', + price_sum: '', + share_cnt: '', + share_view_cnt: '', + is_share: false, + show_vip_link: false, + payed_vip_link: '', + }, + + onLoad() { + }, + + onShow() { + this.getTabBar().init(); + this.init(); + }, + onPullDownRefresh() { + this.init(); + }, + + init() { + this.fetUserInfoHandle(); + }, + + fetUserInfoHandle() { + R.get('/index.php/api/v1/my').then(({ model }) => { + this.setData({ + name: model.real_name || model.nick_name || '微信用户', + phone: model.phone || '-', + share_cnt: model.share_cnt, + share_view_cnt: model.share_view_cnt, + price_sum: F.formatePrice(model.price_sum || 0), + is_share: !!model.is_share, + show_vip_link: model.show_vip_link || false, + payed_vip_link: model.payed_vip_link || '', + }); + }) + }, + getPhoneNumber(e) { + console.log(e.detail.code) // 动态令牌 + console.log(e.detail.errMsg) // 回调信息(成功失败都会返回) + console.log(e.detail.errno) // 错误码(失败时返回) + if (!e.detail.errno) { + R.post('/index.php/api/v1/bind_auth_phone', { code: e.detail.code }).then(() => { + this.setData({ hasPhone: true }) + this.goH5Shop(); + }) + } else { + // e.detail.errMsg + } + }, + goShared() { + wx.switchTab({ + url: '/pages/faxianlist/faxianlist', + }) + }, + goOrder() { + wx.navigateTo({ url: '/pages/paylist/paylist' }) + }, + toVipLink() { + wx.navigateTo({ url: '/pages/webview/webview?url='+encodeURIComponent(this.data.payed_vip_link) }) + }, + goSharelist() { + wx.navigateTo({ url: '/pages/sharelist/sharelist' }) + }, + goInfo() { + wx.navigateTo({ + url: '/pages/usercenter/info', + }) + }, +}); \ No newline at end of file diff --git a/pages/usercenter/index.json b/pages/usercenter/index.json new file mode 100644 index 0000000..3dcbba7 --- /dev/null +++ b/pages/usercenter/index.json @@ -0,0 +1,9 @@ +{ + "navigationBarTitleText": "个人中心", + "usingComponents": { + "t-icon": "tdesign-miniprogram/icon/icon", + "t-link": "tdesign-miniprogram/link/link", + "t-cell": "tdesign-miniprogram/cell/cell" + }, + "enablePullDownRefresh": true +} \ No newline at end of file diff --git a/pages/usercenter/index.less b/pages/usercenter/index.less new file mode 100644 index 0000000..06345f1 --- /dev/null +++ b/pages/usercenter/index.less @@ -0,0 +1,173 @@ +page { + background-color: #f5f5f5; +} + +.header { + background-color: linear-gradient(180deg, #f0f4fc, #fff); + position: relative; + + background-color: rgba(255, 255, 255, 0.8); + box-sizing: border-box; + width: 90%; + margin: 0 auto; + margin-top: -300rpx; + border-radius: 10rpx; + margin-bottom: 20rpx; +} + +.header .info { + background-color: transparent; +} + +.header .info::after { + display: none; +} + +.header .avatar { + width: 96rpx; + height: 96rpx; + border-radius: 50%; + overflow: hidden; +} + +.cb { + top: 10rpx; + right: 100rpx; + height: 530rpx; + width: 750rpx; + background: url('http://cdn.zhonganonline.top/newslist/static/bg_take.jpeg?v=5') no-repeat; + background-position: center center; + background-size: 100% 100%; + z-index: 1; +} + +.vip { + background: linear-gradient(90deg, #f9e9bc, #f2d786); + border-radius: 20rpx; + height: 154rpx; + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 40rpx; + width: 94%; + margin: 0 auto; + box-sizing: border-box; +} + +.vip .dest .a { + color: #775d2f; + font-size: 30rpx; +} + +.vip .dest .b { + color: #775d2f; + opacity: 0.8; + font-size: 22rpx; +} + +.vip .btn { + background-color: #fff; + color: #775d2f; + font-size: 24rpx; + height: 68rpx; + width: 164rpx; + border-radius: 34rpx; + display: flex; + align-items: center; + justify-content: center; +} + +.title_bar { + display: flex; + align-items: center; + justify-content: space-between; + margin-top: 32rpx; + width: 92%; + margin: 0 auto; +} + +.title_bar .title { + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + background-position: left center; + background-size: 100% 100%; + font-size: 32rpx; + color: rgb(53, 58, 71); + height: 34rpx; + width: 132rpx; +} + +.title_bar .btn { + color: #f09759; + font-size: 28rpx; + display: flex; + align-items: center; + background-color: #fff8e9; + padding: 10rpx 20rpx; + border-radius: 6rpx; +} + +.title_bar .btn .t-icon { + margin-right: 4rpx; +} + +.ma20 { + height: 20rpx; + background-color: #f5f5f5; + width: 100%; +} + +.cards_w { + background-color: #fff; + width: 94%; + border-radius: 6rpx; + margin: 0 auto; +} + +.cards_w .cards { + display: flex; + justify-content: space-between; + padding: 30rpx 0; +} + +.cards_w .cards .card { + width: 28%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + background: none; + font-size: 0; + line-height: 24rpx; + + &::after { + display: none; + } +} + +.cards_w .cards .card .txt { + padding-top: 12rpx; + font-size: 24rpx; + color: #333; +} + +.cards_w .cards .card .txt2 { + padding-top: 12rpx; + font-size: 32rpx; + font-weight: bold; + color: #333; +} + +.cards_w .cards .card.hide { + opacity: 0; + pointer-events: none; +} + +.link { + display: flex; + justify-content: space-between; + padding: 30rpx 0; + width: 50%; + margin: 0 auto; + background-color: #fff; + border-radius: 6rpx; +} \ No newline at end of file diff --git a/pages/usercenter/index.wxml b/pages/usercenter/index.wxml new file mode 100644 index 0000000..8963305 --- /dev/null +++ b/pages/usercenter/index.wxml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + {{price_sum}}元 + 总收入 + + + + {{share_cnt}}次 + 总分享 + + + {{share_view_cnt}} + 分享浏览 + + + + + + + + + + + + \ No newline at end of file diff --git a/pages/usercenter/index.wxss b/pages/usercenter/index.wxss new file mode 100644 index 0000000..81b9885 --- /dev/null +++ b/pages/usercenter/index.wxss @@ -0,0 +1,150 @@ +page { + background-color: #f5f5f5; +} +.header { + background-color: linear-gradient(180deg, #f0f4fc, #fff); + position: relative; + background-color: rgba(255, 255, 255, 0.8); + box-sizing: border-box; + width: 90%; + margin: 0 auto; + margin-top: -300rpx; + border-radius: 10rpx; + margin-bottom: 20rpx; +} +.header .info { + background-color: transparent; +} +.header .info::after { + display: none; +} +.header .avatar { + width: 96rpx; + height: 96rpx; + border-radius: 50%; + overflow: hidden; +} +.cb { + top: 10rpx; + right: 100rpx; + height: 530rpx; + width: 750rpx; + background: url('http://cdn.zhonganonline.top/newslist/static/bg_take.jpeg?v=5') no-repeat; + background-position: center center; + background-size: 100% 100%; + z-index: 1; +} +.vip { + background: linear-gradient(90deg, #f9e9bc, #f2d786); + border-radius: 20rpx; + height: 154rpx; + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 40rpx; + width: 94%; + margin: 0 auto; + box-sizing: border-box; +} +.vip .dest .a { + color: #775d2f; + font-size: 30rpx; +} +.vip .dest .b { + color: #775d2f; + opacity: 0.8; + font-size: 22rpx; +} +.vip .btn { + background-color: #fff; + color: #775d2f; + font-size: 24rpx; + height: 68rpx; + width: 164rpx; + border-radius: 34rpx; + display: flex; + align-items: center; + justify-content: center; +} +.title_bar { + display: flex; + align-items: center; + justify-content: space-between; + margin-top: 32rpx; + width: 92%; + margin: 0 auto; +} +.title_bar .title { + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; + background-position: left center; + background-size: 100% 100%; + font-size: 32rpx; + color: #353a47; + height: 34rpx; + width: 132rpx; +} +.title_bar .btn { + color: #f09759; + font-size: 28rpx; + display: flex; + align-items: center; + background-color: #fff8e9; + padding: 10rpx 20rpx; + border-radius: 6rpx; +} +.title_bar .btn .t-icon { + margin-right: 4rpx; +} +.ma20 { + height: 20rpx; + background-color: #f5f5f5; + width: 100%; +} +.cards_w { + background-color: #fff; + width: 94%; + border-radius: 6rpx; + margin: 0 auto; +} +.cards_w .cards { + display: flex; + justify-content: space-between; + padding: 30rpx 0; +} +.cards_w .cards .card { + width: 28%; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + background: none; + font-size: 0; + line-height: 24rpx; +} +.cards_w .cards .card::after { + display: none; +} +.cards_w .cards .card .txt { + padding-top: 12rpx; + font-size: 24rpx; + color: #333; +} +.cards_w .cards .card .txt2 { + padding-top: 12rpx; + font-size: 32rpx; + font-weight: bold; + color: #333; +} +.cards_w .cards .card.hide { + opacity: 0; + pointer-events: none; +} +.link { + display: flex; + justify-content: space-between; + padding: 30rpx 0; + width: 50%; + margin: 0 auto; + background-color: #fff; + border-radius: 6rpx; +} diff --git a/pages/usercenter/info.js b/pages/usercenter/info.js new file mode 100644 index 0000000..02451ab --- /dev/null +++ b/pages/usercenter/info.js @@ -0,0 +1,31 @@ +import R from '../../utils/request'; + + +Page({ + data: { + name: '', + }, + + onLoad() { + }, + + onShow() { + R.get('/index.php/api/v1/my').then(({ model }) => { + this.setData({ + name: model.real_name || model.nick_name || '微信用户', + }); + }) + }, + onSubmit(){ + if(!this.data.name.trim()){ + wx.showToast({ + title: '请填写姓名', + icon: 'none', + }); + return; + } + R.post('/index.php/api/v1/set_name',{name:this.data.name.trim()}).then(({ model }) => { + wx.navigateBack(); + }) + } +}); \ No newline at end of file diff --git a/pages/usercenter/info.json b/pages/usercenter/info.json new file mode 100644 index 0000000..8be5b4b --- /dev/null +++ b/pages/usercenter/info.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "个人信息", + "backgroundTextStyle": "light", + "usingComponents": { + "t-input": "tdesign-miniprogram/input/input", + "t-button": "tdesign-miniprogram/button/button" + } +} \ No newline at end of file diff --git a/pages/usercenter/info.wxml b/pages/usercenter/info.wxml new file mode 100644 index 0000000..7d57fc3 --- /dev/null +++ b/pages/usercenter/info.wxml @@ -0,0 +1,8 @@ + + + + + + 确认 + + \ No newline at end of file diff --git a/pages/usercenter/info.wxss b/pages/usercenter/info.wxss new file mode 100644 index 0000000..48e30df --- /dev/null +++ b/pages/usercenter/info.wxss @@ -0,0 +1,7 @@ +page { + background-color: #f5f5f5; +} +.btns{ + padding: 20rpx 40rpx; + box-sizing: border-box; +} \ No newline at end of file diff --git a/pages/webview/webview.js b/pages/webview/webview.js new file mode 100644 index 0000000..b3586b9 --- /dev/null +++ b/pages/webview/webview.js @@ -0,0 +1,13 @@ + +Page({ + data: { + url: '', + }, + onLoad(options) { + let { url } = options; + console.log('url',url); + const user_id = wx.getStorageSync('user_id'); + url = url.replace('${user_id}', user_id); + this.setData({ url: decodeURIComponent(url) }); + }, +}) \ No newline at end of file diff --git a/pages/webview/webview.json b/pages/webview/webview.json new file mode 100644 index 0000000..5acf6ef --- /dev/null +++ b/pages/webview/webview.json @@ -0,0 +1,5 @@ +{ + "navigationBarTitleText": " ", + "backgroundTextStyle": "light", + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/webview/webview.wxml b/pages/webview/webview.wxml new file mode 100644 index 0000000..d3e700b --- /dev/null +++ b/pages/webview/webview.wxml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/pages/webview/webview.wxss b/pages/webview/webview.wxss new file mode 100644 index 0000000..229fba5 --- /dev/null +++ b/pages/webview/webview.wxss @@ -0,0 +1 @@ +/* pages/webview/webview.wxss */ \ No newline at end of file diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..fdae2cd --- /dev/null +++ b/project.config.json @@ -0,0 +1,78 @@ +{ + "description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", + "setting": { + "urlCheck": true, + "es6": true, + "enhance": true, + "postcss": true, + "preloadBackgroundData": false, + "minified": true, + "newFeature": false, + "coverView": true, + "nodeModules": true, + "autoAudits": false, + "showShadowRootInWxmlPanel": true, + "scopeDataCheck": false, + "uglifyFileName": false, + "checkInvalidKey": true, + "checkSiteMap": true, + "uploadWithSourceMap": true, + "compileHotReLoad": false, + "lazyloadPlaceholderEnable": false, + "useMultiFrameRuntime": true, + "ignoreDevUnusedFiles": false, + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "enableEngineNative": false, + "useIsolateContext": true, + "userConfirmedBundleSwitch": false, + "packNpmManually": false, + "packNpmRelationList": [], + "minifyWXSS": true, + "disableUseStrict": false, + "minifyWXML": true, + "showES6CompileOption": false, + "useCompilerPlugins": false, + "ignoreUploadUnusedFiles": true, + "useStaticServer": true, + "compileWorklet": false, + "localPlugins": false, + "condition": false, + "swc": false, + "disableSWC": true + }, + "compileType": "miniprogram", + "simulatorType": "wechat", + "simulatorPluginLibVersion": {}, + "condition": { + "miniprogram": { + "list": [ + { + "name": "首页入口", + "pathName": "pages/home/home", + "query": "", + "scene": null + }, + { + "name": "示例页-个人中心", + "pathName": "pages/usercenter/index", + "query": "", + "scene": null + } + ] + } + }, + "editorSetting": { + "tabIndent": "insertSpaces", + "tabSize": 2 + }, + "packOptions": { + "ignore": [], + "include": [] + }, + "appid": "wx1a5ce23035f68f08", + "libVersion": "3.5.8" +} \ 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/style/iconfont.wxss b/style/iconfont.wxss new file mode 100644 index 0000000..23df272 --- /dev/null +++ b/style/iconfont.wxss @@ -0,0 +1,306 @@ +@font-face { + font-family: 'wr'; + src: url('https://cdn3.codesign.qq.com/icons/gqxWyZ1yMJZmVXk/Yyg5Zp2LG8292lK/iconfont.woff?t=cfc62dd36011e60805f5c3ad1a20b642') + format('woff2'); +} + +.wr { + font-family: 'wr' !important; + font-size: 32rpx; + font-style: normal; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} +.wr-deliver:before { + content: '\e033'; +} +.wr-indent_close:before { + content: '\e041'; +} +.wr-edit:before { + content: '\e002'; +} +.wr-succeed:before { + content: '\e00d'; +} +.wr-goods_return:before { + content: '\e03c'; +} +.wr-wallet:before { + content: '\e051'; +} +.wr-package:before { + content: '\e047'; +} +.wr-comment:before { + content: '\e037'; +} +.wr-exchang:before { + content: '\e03e'; +} +.wr-credit_card:before { + content: '\e035'; +} +.wr-service:before { + content: '\e04a'; +} +.wr-shop_bag:before { + content: '\e02a'; +} +.wr-goods_refund:before { + content: '\e03d'; +} +.wr-check:before { + content: '\e053'; +} +.wr-wechat:before { + content: '\e065'; +} +.wr-cartAdd:before { + content: '\e05d'; +} +.wr-home:before { + content: '\e020'; +} +.wr-person:before { + content: '\e02c'; +} +.wr-cart:before { + content: '\e023'; +} +.wr-location:before { + content: '\e016'; +} +.wr-arrow_forward:before { + content: '\e012'; +} +.wr-close:before { + content: '\e021'; +} +.wr-search:before { + content: '\e011'; +} +.wr-clear_filled:before { + content: '\e027'; +} +.wr-arrow_drop_up:before { + content: '\e071'; +} +.wr-arrow_drop_down:before { + content: '\e070'; +} +.wr-filter:before { + content: '\e038'; +} +.wr-copy:before { + content: '\e001'; +} +.wr-arrow_back:before { + content: '\e003'; +} +.wr-add_circle:before { + content: '\e004'; +} +.wr-Download:before { + content: '\e006'; +} +.wr-map:before { + content: '\e007'; +} +.wr-store:before { + content: '\e008'; +} +.wr-movie:before { + content: '\e00a'; +} +.wr-done:before { + content: '\e00b'; +} +.wr-minus:before { + content: '\e00c'; +} +.wr-list:before { + content: '\e00e'; +} +.wr-expand_less:before { + content: '\e00f'; +} +.wr-person_add:before { + content: '\e010'; +} +.wr-Photo:before { + content: '\e013'; +} +.wr-preview:before { + content: '\e014'; +} +.wr-remind:before { + content: '\e015'; +} + +.wr-info:before { + content: '\e017'; +} +.wr-expand_less_s:before { + content: '\e018'; +} +.wr-arrow_forward_s:before { + content: '\e019'; +} +.wr-expand_more_s:before { + content: '\e01a'; +} +.wr-share:before { + content: '\e01d'; +} +.wr-notify:before { + content: '\e01e'; +} +.wr-add:before { + content: '\e01f'; +} +.wr-Home:before { + content: '\e020'; +} +.wr-delete:before { + content: '\e022'; +} +.wr-error:before { + content: '\e025'; +} +.wr-sort:before { + content: '\e028'; +} +.wr-sort_filled:before { + content: '\e029'; +} +.wr-shop_bag_filled:before { + content: '\e02b'; +} + +.wr-person_filled:before { + content: '\e02d'; +} +.wr-cart_filled:before { + content: '\e02e'; +} +.wr-home_filled:before { + content: '\e02f'; +} +.wr-add_outline:before { + content: '\e030'; +} + +.wr-compass:before { + content: '\e034'; +} +.wr-goods_exchange:before { + content: '\e03a'; +} +.wr-group_buy:before { + content: '\e03b'; +} +.wr-group:before { + content: '\e03f'; +} +.wr-indent_goods:before { + content: '\e040'; +} +.wr-help:before { + content: '\e042'; +} +.wr-group_takeout:before { + content: '\e043'; +} +.wr-label:before { + content: '\e044'; +} +.wr-indent_wating:before { + content: '\e045'; +} +.wr-member:before { + content: '\e046'; +} + +.wr-scanning:before { + content: '\e04b'; +} +.wr-tv:before { + content: '\e04d'; +} +.wr-to_top:before { + content: '\e04f'; +} +.wr-visibility_off:before { + content: '\e050'; +} +.wr-error-1:before { + content: '\e052'; +} + +.wr-arrow_right:before { + content: '\e054'; +} +.wr-arrow_left:before { + content: '\e056'; +} +.wr-picture_filled:before { + content: '\e057'; +} +.wr-navigation:before { + content: '\e058'; +} +.wr-telephone:before { + content: '\e059'; +} +.wr-indent_time:before { + content: '\e05c'; +} +.wr-cart_add:before { + content: '\e05d'; +} +.wr-classify:before { + content: '\e060'; +} +.wr-place:before { + content: '\e063'; +} +.wr-wechat_pay:before { + content: '\e064'; +} +.wr-security:before { + content: '\e066'; +} +.wr-alarm:before { + content: '\e067'; +} +.wr-person-1:before { + content: '\e068'; +} +.wr-open_in_new:before { + content: '\e069'; +} +.wr-uncheck:before { + content: '\e06b'; +} +.wr-thumb_up:before { + content: '\e06c'; +} +.wr-thumb_up_filled:before { + content: '\e06d'; +} +.wr-star:before { + content: '\e06e'; +} +.wr-star_filled:before { + content: '\e06f'; +} +.wr-cards:before { + content: '\e072'; +} +.wr-picture_error_filled:before { + content: '\e076'; +} +.wr-discount:before { + content: '\e077'; +} diff --git a/style/theme.wxss b/style/theme.wxss new file mode 100644 index 0000000..bb1249e --- /dev/null +++ b/style/theme.wxss @@ -0,0 +1,47 @@ +/* 主题定制 */ +.t-input { + --td-input-placeholder-text-color: #bbbbbb; + --td-input-text-color: #333333; +} + +.t-tab-bar { + --td-tab-bar-color: #bbb; + --td-tab-bar-active-color: #333; +} + +.t-cascader { + --td-cascader-active-color: #fa4126; +} + +.t-switch { + --td-switch-checked-color: #34c759; +} + +.t-button { + --td-button-font-weight: 500; + --td-button-medium-font-size: 32rpx; + --td-button-default-color: #fff; + --td-button-default-bg-color: #fa4126; + --td-button-default-border-color: #fa4126; + --td-button-default-disabled-color: #fff; + --td-button-default-disabled-bg: #cccccc; + --td-button-default-disabled-border-color: #cccccc; + --td-button-default-active-bg-color: #fa4126; + --td-button-default-active-border-color: #fa4126; +} + +.t-textarea { + --td-textarea-placeholder-color: #bbb; +} + +.t-checkbox { + --td-checkbox-icon-checked-color: #fa4126; +} + +.dialog__button-confirm { + color: #fa4126 !important; +} + +.dialog__button-cancel { + color: #aeb3b7 !important; +} diff --git a/utils/constant.js b/utils/constant.js new file mode 100644 index 0000000..48466d4 --- /dev/null +++ b/utils/constant.js @@ -0,0 +1,29 @@ +const _ = { + // cdnHost: 'http://civcar2.zhonganonline.top/newslist', + // apiHost: 'http://civcar2.zhonganonline.top/newslist', + cdnHost: 'http://cdn.liiistem.cn/liiistem', + apiHost: 'https://prxy.liiistem.cn/liiistem', +}; +if (wx.getStorageSync('mode') == 'dev') { + _.cdnHost = 'http://civcar2.zhonganonline.top/liiistem'; + _.apiHost = 'http://civcar2.zhonganonline.top/liiistem'; +} + +export const STATUS_LIST = [{ + key: 'init', + label: '待审核' +}, +{ + key: 'resolve', + label: '审核通过' +}, +{ + key: 'reject', + label: '审核未通过' +}, +] +export const STATUS_MAP = STATUS_LIST.reduce((r, c) => { + r[c.key] = c; + return r; +}, {}) +export default _; \ No newline at end of file diff --git a/utils/func.js b/utils/func.js new file mode 100644 index 0000000..1f16754 --- /dev/null +++ b/utils/func.js @@ -0,0 +1,162 @@ +import C from './constant.js'; +export const getHost = () => { + return C.apiHost; +}; +export const isDev = () => { + return true; +} +export const parseDate = (time, type = 1) => { + const val = [time.getFullYear(), time.getMonth() + 1, time.getDate()].map((o) => { return o < 10 ? '0' + o : o }); + const val2 = [time.getHours(), time.getMinutes(), time.getSeconds()].map((o) => { return o < 10 ? '0' + o : o }); + if (type === 1) { + return val.join('-'); + } + if (type === 2) { + return val2.join(':'); + } + if (type === 3) { + return [val[0], '年', val[1], '月', val[2], '日'].join(''); + } + if (type === 4) { + return val[0] + '年'; + } + if (type === 5) { + return [val[1], '月'].join(''); + } + if (type === 6) { + return [val[1], '月', val[2], '日'].join(''); + } + if (type === 7) { + return val.join('.'); + } + return val.join('-') + ' ' + val2.join(':'); +} + + +export const safeStrToDate = (str) => { + const arr = str.split(/[-\ \:]/g); + const arr2 = [0, 0, 0, 0, 0, 0]; + arr.map((one, idx) => { + arr2[idx] = one * 1; + }); + if (arr2[1] > 0) { + arr2[1] -= 1; + } + return new Date(arr2[0], arr2[1], arr2[2], arr2[3], arr2[4], arr2[5]); +} + +export const sizeTool = (size) => { + if (size > 1024 * 1024 * 1024) { + return (size / 1024 / 1024 / 1024).toFixed(2) + 'G'; + } + if (size > 1024 * 1024) { + return (size / 1024 / 1024).toFixed(2) + 'M'; + } + if (size > 1024) { + return (size / 1024).toFixed(2) + 'K'; + } + return size + 'B' +} + +export const getQueryString = (params) => { + const list = []; + for (const k in params) { + if (!(params[k] == undefined || params[k] == null)) { + list.push([encodeURIComponent(k), encodeURIComponent(params[k])].join('=')); + } + } + return list.join('&'); +} + +export const parseQueryString = (str) => { + const l = str.split('&'); + const m = {}; + l.forEach((o) => { + const _ = o.split('='); + m[decodeURIComponent(_[0])] = decodeURIComponent(_[1] || ''); + }) + return m; +} + +export const filterProperties = (obj, propKeys) => { + if (propKeys.length == 0) { + return { ...obj }; + } + const reObj = {}; + propKeys.map((k) => { + reObj[k] = obj[k]; + }); + return reObj; +} + +export const filterPropertiesList = (list, propKeys) => { + return list.map((obj => filterProperties(obj, propKeys))); +} + + +export const secToTimeStr = (n) => { + const h = Math.floor(n * 1.0 / 60 / 60); + const m = Math.floor((n - h * 60 * 60) / 60); + const s = n % 60; + return h + '时' + m + '分' + s + '秒'; +} + +export const dateToWeek = (date) => { + const arr = '日一二三四五六'.split(''); + return arr[date.getDay()]; +} + +export const fixPage = (pageData, oldPage) => { + // console.log('fixPage', pageData.page, oldPage); + const { page, pageSize, total } = pageData; + if (total == 0) { + return { + ...pageData, + page: 1, pageSize, total: 0 + }; + } + const maxPage = Math.ceil(total * 1.0 / pageSize); + if (oldPage > maxPage) { + return { + ...pageData, + list: [], + page: oldPage, pageSize, total: 0 + }; + } + return { + ...pageData, + page, pageSize, total + }; +} + + +// 分转元,并移除小数点后多余的0 +export const formatePrice = (price) => { + return (price / 100).toFixed(2).replace(/\.00$/, '') +} +// 时间(12:22)加上分钟后的时间 +export const timeAddMinute = (time, minute) => { + const tmpTime = safeStrToDate('2020-01-01 ' + time + ':00').getTime() + minute * 60 * 1000; + return parseDate(new Date(tmpTime), 9); +} + +// 手机号隐藏中间几位 +export const hidePhone = (phone) => { + return (phone || '').replace(/(\d{3})\d{4}(\d{4})/, '$1****$2'); +} + +export const fix0 = (n) => { + if (!/[0-9\.]+/.test(n + '')) { + return 0; + } + const t = n + ''; + if (n.indexOf('.') == -1) { + return t; + } + const tt = t.split('.'); + const f0 = (tt[1].split('').reverse().join('') * 1 + '').split('').reverse().join(''); + if (f0 == 0) { + return tt[0]; + } + return [tt[0], f0].join('.'); +} \ No newline at end of file diff --git a/utils/getPermission.js b/utils/getPermission.js new file mode 100644 index 0000000..e6a64cb --- /dev/null +++ b/utils/getPermission.js @@ -0,0 +1,45 @@ +const getPermission = ({ code, name }) => { + return new Promise((resolve, reject) => { + wx.getSetting({ + success: (res) => { + if (res.authSetting[code] === false) { + wx.showModal({ + title: `获取${name}失败`, + content: `获取${name}失败,请在【右上角】-小程序【设置】项中,将【${name}】开启。`, + confirmText: '去设置', + confirmColor: '#FA550F', + cancelColor: '取消', + success(res) { + if (res.confirm) { + wx.openSetting({ + success(settinRes) { + if (settinRes.authSetting[code] === true) { + resolve(); + } else { + console.warn('用户未打开权限', name, code); + reject(); + } + }, + }); + } else { + reject(); + } + }, + fail() { + reject(); + }, + }); + } else { + resolve(); + } + }, + fail() { + reject(); + }, + }); + }); +}; + +module.exports = { + getPermission, +}; diff --git a/utils/log.js b/utils/log.js new file mode 100644 index 0000000..451e060 --- /dev/null +++ b/utils/log.js @@ -0,0 +1,53 @@ +const A = { + isLog: false, + logList: [], +} +A.info = (msg) => { + if (A.isLog) { + return; + } + console.log('info', msg); + A.logList.push({ + time: new Date(), + msg: msg, + type: 'info', + }); + // console.log('logList', A.logList); +} +A.warn = (msg) => { + if (A.isLog) { + return; + } + console.log('warn', msg); + A.logList.push({ + time: new Date(), + msg: msg, + type: 'warn', + }); +} +A.error = (msg) => { + if (A.isLog) { + return; + } + console.log('error', msg); + A.logList.push({ + time: new Date(), + msg: msg, + type: 'error', + }); +} +A.getLogList = (type) => { + if (type) { + return A.logList.filter((o) => { + return o.type == type; + }) + } + console.log('llllll', A.logList, type); + return A.logList; +} +A.setIslog = (f) => { + // console.log('setIslog', f); + A.isLog = f; +} + +module.exports = A \ No newline at end of file diff --git a/utils/mock.js b/utils/mock.js new file mode 100644 index 0000000..27f13e8 --- /dev/null +++ b/utils/mock.js @@ -0,0 +1,51 @@ +/** + * 随机打散字符串 + * @param {number} n 长度 + * @param {string} str 字符串 + * @returns + */ +function generateMixed(n, str) { + var res = ''; + for (var i = 0; i < n; i++) { + var id = Math.ceil(Math.random() * 35); + res += str[id]; + } + return res; +} + +/** + * 生成随机数 + * @param {number} min 最小值 + * @param {number} max 最大值 + * @returns + */ +function getRandomNum(min, max) { + var range = max - min; + var rand = Math.random(); + return min + Math.round(rand * range); +} + +/** + * 生成随机IP + * @returns + */ +function mockIp() { + return `10.${getRandomNum(1, 254)}.${getRandomNum(1, 254)}.${getRandomNum( + 1, + 254, + )}`; +} + +function mockReqId() { + return `${getRandomNum(100000, 999999)}.${new Date().valueOf()}${getRandomNum( + 1000, + 9999, + )}.${getRandomNum(10000000, 99999999)}`; +} + +module.exports = { + generateMixed, + mockIp, + mockReqId, + getRandomNum, +}; diff --git a/utils/request.js b/utils/request.js new file mode 100644 index 0000000..054a77c --- /dev/null +++ b/utils/request.js @@ -0,0 +1,226 @@ +import * as F from './func.js'; +const Log = require('./log.js'); +import C from './constant.js'; +let lockToLogin = false; +const login = () => { + const user_id = wx.getStorageSync('user_id'); + if (user_id) { + return Promise.resolve(user_id); + } + // return Promise.resolve(); + return new Promise((resolve, reject) => { + wx.login({ + success({ code }) { + console.log('aaaa', code); + // code = 'test'; + // code:'test' + post('/index.php/api/v1/wx_login', { code }, true).then(({ model }) => { + console.log('wx_login', model); + wx.setStorageSync('user_id', model.user_id); + resolve(model); + }).catch((e) => { + reject(e) + }) + }, + fail(e) { + reject(e) + } + }) + }); +} +const post = (path, params, notLogin = false) => { + Log.info('post 请求:' + path + 'params:' + JSON.stringify(params)); + const _ = ((resolve, reject) => { + const user_id = wx.getStorageSync('user_id'); + if (!user_id && !notLogin) { + return reject(-1002); + } + wx.request({ + url: F.getHost() + path, + data: params, + header: { + Cookie: 'user_id=' + user_id, + }, + method: 'POST', + success: (res) => { + console.log('res', res); + const { + data, + statusCode, + cookies + } = res; + if (statusCode != 200) { + wx.showToast({ + icon:'none', + title: 'statusCode:' + statusCode + }); + Log.error('post 请求失败1:' + statusCode + '|' + path + ' params:' + JSON.stringify(params)); + reject(-1); + } else { + const message = data.errorMsg || data.message; + const errorCode = data.errorCode; + if (errorCode == -1000) { + wx.showToast({ + icon:'none', + title: "登录超时,请重新登录" + }); + if (!lockToLogin) { + lockToLogin = true; + wx.navigateTo({ + url: '/pages/login/index' + }); + setTimeout(() => { + lockToLogin = false; + }, 1000) + } + reject(-4); + } else if (errorCode < 0) { + wx.showToast({ + icon:'none', + title: message || errorCode + '请求失败' , + }); + Log.error('post 请求失败2:' + message + '|' + path + ' params:' + JSON.stringify(params)); + reject(-3); + } else { + resolve(data); + } + } + }, + fail: ({ + errMsg, + errno + }) => { + wx.showToast({ + icon:'none', + title: '接口异常:' + errMsg + }); + console.error('post fail:', errMsg, errno); + Log.error('post error:' + errMsg + '|errno:' + errno + '|' + path + ' params:' + JSON.stringify(params)); + reject(-2); + } + }); + }) + + if (notLogin) { + return new Promise(_); + } else { + return login().then(() => new Promise(_)); + } +} +const get = (path, params, notLogin = false) => { + Log.info('get 请求:' + path + 'params:' + JSON.stringify(params)); + const _ = ((resolve, reject) => { + const user_id = wx.getStorageSync('user_id'); + if (!user_id && !notLogin) { + return reject(-1002); + } + wx.request({ + url: F.getHost() + path, + data: params, + header: { + Cookie: 'user_id=' + user_id, + }, + method: 'GET', + success: ({ + data, + statusCode, + cookies + }) => { + if (statusCode != 200) { + wx.showToast({ + icon:'none', + title: 'statusCode:' + statusCode + }); + Log.error('get 请求失败1:' + statusCode + '|' + path + ' params:' + JSON.stringify(params)); + reject(-1); + } else { + const message = data.errorMsg || data.message; + const errorCode = data.errorCode; + if (errorCode == -1000) { + wx.showToast({ + icon:'none', + title: "登录超时,请重新登录" + }); + if (!lockToLogin) { + lockToLogin = true; + wx.navigateTo({ + url: '/pages/login/index' + }); + setTimeout(() => { + lockToLogin = false; + }, 1000) + } + reject(-4); + } else if (errorCode < 0) { + wx.showToast({ + icon:'none', + title: message || errorCode + '请求失败' , + }); + Log.error('get 请求失败2:' + message + '|' + path + ' params:' + JSON.stringify(params)); + reject(-3); + } else { + resolve(data); + } + } + }, + fail: ({ + errMsg, + errno + }) => { + wx.showToast({ + icon:'none', + title: '接口异常:' + errMsg + }); + console.error('get fail:', errMsg, errno); + Log.error('get error:' + errMsg + '|errno:' + errno + '|' + path + ' params:' + JSON.stringify(params)); + reject(-2); + } + }); + }) + + if (notLogin) { + return new Promise(_); + } else { + return login().then(() => new Promise(_)); + } +} +const upload = (params, name, filePath, processCb) => { + const _ = new Promise((resolve, reject) => { + const user_id = wx.getStorageSync('user_id'); + const task = wx.uploadFile({ + url: F.getHost() + '/index.php/api/v1/wx_upload', + formData: params, + name, + filePath, + header: { + Cookie: 'user_id=' + user_id, + 'Content-Type': 'multipart/form-data', + }, + timeout: 120000, + method: 'POST', + success: (res) => { + resolve(res); + }, + fail: (res) => { + const { + errMsg, + errno + } = res; + console.error('post fail:', errMsg, errno); + Log.error('upload post fail:' + errMsg + '|errno' + errno); + reject(res); + } + }); + if (processCb) { + task.onProgressUpdate(processCb); + } + }) + + return login().then(() => _); +} +export default { + login, + post, + get, + upload, +}; \ No newline at end of file diff --git a/utils/requestAct1.js b/utils/requestAct1.js new file mode 100644 index 0000000..173837c --- /dev/null +++ b/utils/requestAct1.js @@ -0,0 +1,203 @@ +import * as F from './func.js'; +const Log = require('./log.js'); +import C from './constant.js'; +let lockToLogin = false; +const login = () => { + return Promise.resolve(); +} +const post = (path, params, notLogin = false) => { + Log.info('post 请求:' + path + 'params:' + JSON.stringify(params)); + const _ = new Promise((resolve, reject) => { + const user_id = wx.getStorageSync('act_user_id'); + if (!user_id && !notLogin) { + return reject(-1001); + } + wx.request({ + url: F.getHost() + path, + data: params, + header: { + Cookie: 'act_user_id=' + user_id, + }, + method: 'POST', + success: (res) => { + console.log('res', res); + const { + data, + statusCode, + cookies + } = res; + if (statusCode != 200) { + wx.showToast({ + icon: 'none', + title: 'statusCode:' + statusCode + }); + Log.error('post 请求失败1:' + statusCode + '|' + path + ' params:' + JSON.stringify(params)); + reject(-1); + } else { + const message = data.errorMsg || data.message; + const errorCode = data.errorCode; + if (errorCode == -1000) { + wx.showToast({ + icon: 'none', + title: "登录超时,请重新登录" + }); + if (!lockToLogin) { + lockToLogin = true; + wx.navigateTo({ + url: '/pages/login/index' + }); + setTimeout(() => { + lockToLogin = false; + }, 1000) + } + reject(-4); + } else if (errorCode < 0) { + wx.showToast({ + icon: 'none', + title: message || errorCode + '请求失败' + }); + Log.error('post 请求失败2:' + message + '|' + path + ' params:' + JSON.stringify(params)); + reject(-3); + } else { + resolve(data); + } + } + }, + fail: ({ + errMsg, + errno + }) => { + wx.showToast({ + icon: 'none', + title: '接口异常:' + errMsg + }); + console.error('post fail:', errMsg, errno); + Log.error('post error:' + errMsg + '|errno:' + errno + '|' + path + ' params:' + JSON.stringify(params)); + reject(-2); + } + }); + }) + + if (notLogin) { + return _; + } else { + return login().then(() => _); + } +} +const get = (path, params, notLogin = false) => { + Log.info('get 请求:' + path + 'params:' + JSON.stringify(params)); + const _ = new Promise((resolve, reject) => { + const user_id = wx.getStorageSync('act_user_id'); + if (!user_id && !notLogin) { + return reject(-1001); + } + wx.request({ + url: F.getHost() + path, + data: params, + header: { + Cookie: 'act_user_id=' + user_id, + }, + method: 'GET', + success: ({ + data, + statusCode, + cookies + }) => { + if (statusCode != 200) { + wx.showToast({ + icon: 'none', + title: 'statusCode:' + statusCode + }); + Log.error('get 请求失败1:' + statusCode + '|' + path + ' params:' + JSON.stringify(params)); + reject(-1); + } else { + const message = data.errorMsg || data.message; + const errorCode = data.errorCode; + if (errorCode == -1000) { + wx.showToast({ + icon: 'none', + title: "登录超时,请重新登录" + }); + if (!lockToLogin) { + lockToLogin = true; + wx.navigateTo({ + url: '/pages/login/index' + }); + setTimeout(() => { + lockToLogin = false; + }, 1000) + } + reject(-4); + } else if (errorCode < 0) { + wx.showToast({ + icon: 'none', + title: message || errorCode + '请求失败' + }); + Log.error('get 请求失败2:' + message + '|' + path + ' params:' + JSON.stringify(params)); + reject(-3); + } else { + resolve(data); + } + } + }, + fail: ({ + errMsg, + errno + }) => { + wx.showToast({ + icon: 'none', + title: '接口异常:' + errMsg + }); + console.error('get fail:', errMsg, errno); + Log.error('get error:' + errMsg + '|errno:' + errno + '|' + path + ' params:' + JSON.stringify(params)); + reject(-2); + } + }); + }) + + if (notLogin) { + return _; + } else { + return login().then(() => _); + } +} +const upload = (params, name, filePath, processCb) => { + const _ = new Promise((resolve, reject) => { + const user_id = wx.getStorageSync('act_user_id'); + const task = wx.uploadFile({ + url: F.getHost() + '/index.php/api/act1/wx_upload', + formData: params, + name, + filePath, + header: { + Cookie: 'act_user_id=' + user_id, + 'Content-Type': 'multipart/form-data', + }, + timeout: 120000, + method: 'POST', + success: (res) => { + resolve(res); + }, + fail: (res) => { + const { + errorMsg, + errorCode + } = res; + console.error('post fail:', errorMsg, errorCode); + Log.error('upload post fail:' + errorMsg + '|errorCode' + errorCode); + reject(res); + } + }); + if (processCb) { + task.onProgressUpdate(processCb); + } + }) + + return login().then(() => _); +} +export default { + login, + post, + get, + upload, +}; \ No newline at end of file diff --git a/utils/util.js b/utils/util.js new file mode 100644 index 0000000..4f0ec66 --- /dev/null +++ b/utils/util.js @@ -0,0 +1,133 @@ +import dayjs from 'dayjs'; + +const formatTime = (date, template) => dayjs(date).format(template); + +/** + * 格式化价格数额为字符串 + * 可对小数部分进行填充,默认不填充 + * @param price 价格数额,以分为单位! + * @param fill 是否填充小数部分 0-不填充 1-填充第一位小数 2-填充两位小数 + */ +function priceFormat(price, fill = 0) { + if (isNaN(price) || price === null || price === Infinity) { + return price; + } + + let priceFormatValue = Math.round(parseFloat(`${price}`) * 10 ** 8) / 10 ** 8; // 恢复精度丢失 + priceFormatValue = `${Math.ceil(priceFormatValue) / 100}`; // 向上取整,单位转换为元,转换为字符串 + if (fill > 0) { + // 补充小数位数 + if (priceFormatValue.indexOf('.') === -1) { + priceFormatValue = `${priceFormatValue}.`; + } + const n = fill - priceFormatValue.split('.')[1]?.length; + for (let i = 0; i < n; i++) { + priceFormatValue = `${priceFormatValue}0`; + } + } + return priceFormatValue; +} + +/** + * 获取cdn裁剪后链接 + * + * @param {string} url 基础链接 + * @param {number} width 宽度,单位px + * @param {number} [height] 可选,高度,不填时与width同值 + */ +const cosThumb = (url, width, height = width) => { + if (url.indexOf('?') > -1) { + return url; + } + + if (url.indexOf('http://') === 0) { + url = url.replace('http://', 'https://'); + } + + return `${url}?imageMogr2/thumbnail/${~~width}x${~~height}`; +}; + +const get = (source, paths, defaultValue) => { + if (typeof paths === 'string') { + paths = paths + .replace(/\[/g, '.') + .replace(/\]/g, '') + .split('.') + .filter(Boolean); + } + const { length } = paths; + let index = 0; + while (source != null && index < length) { + source = source[paths[index++]]; + } + return source === undefined || index === 0 ? defaultValue : source; +}; +let systemWidth = 0; +/** 获取系统宽度,为了减少启动消耗所以在函数里边做初始化 */ +export const loadSystemWidth = () => { + if (systemWidth) { + return systemWidth; + } + + try { + ({ screenWidth: systemWidth, pixelRatio } = wx.getSystemInfoSync()); + } catch (e) { + systemWidth = 0; + } + return systemWidth; +}; + +/** + * 转换rpx为px + * + * @description + * 什么时候用? + * - 布局(width: 172rpx)已经写好, 某些组件只接受px作为style或者prop指定 + * + */ +const rpx2px = (rpx, round = false) => { + loadSystemWidth(); + + // px / systemWidth = rpx / 750 + const result = (rpx * systemWidth) / 750; + + if (round) { + return Math.floor(result); + } + + return result; +}; + +/** + * 手机号码*加密函数 + * @param {string} phone 电话号 + * @returns + */ +const phoneEncryption = (phone) => { + return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2'); +}; + +// 内置手机号正则字符串 +const innerPhoneReg = + '^1(?:3\\d|4[4-9]|5[0-35-9]|6[67]|7[0-8]|8\\d|9\\d)\\d{8}$'; + +/** + * 手机号正则校验 + * @param phone 手机号 + * @param phoneReg 正则字符串 + * @returns true - 校验通过 false - 校验失败 + */ +const phoneRegCheck = (phone) => { + const phoneRegExp = new RegExp(innerPhoneReg); + return phoneRegExp.test(phone); +}; + +module.exports = { + formatTime, + priceFormat, + cosThumb, + get, + rpx2px, + phoneEncryption, + phoneRegCheck, +};