Repository: PrototypeFunction/PlanMaster Branch: master Commit: ffd516cb1421 Files: 35 Total size: 62.6 KB Directory structure: gitextract_izy1lf9k/ ├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── app.js ├── app.json ├── app.wxss ├── components/ │ └── sponsor/ │ ├── sponsor.js │ ├── sponsor.json │ ├── sponsor.wxml │ └── sponsor.wxss ├── pages/ │ ├── ad/ │ │ ├── ad.js │ │ └── ad.wxml │ ├── changePlan/ │ │ ├── changePlan.js │ │ ├── changePlan.json │ │ ├── changePlan.wxml │ │ └── changePlan.wxss │ ├── detail/ │ │ ├── detail.js │ │ ├── detail.json │ │ ├── detail.wxml │ │ └── detail.wxss │ ├── feedback/ │ │ ├── feedback.js │ │ ├── feedback.json │ │ └── feedback.wxml │ ├── index/ │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── newCard/ │ │ ├── newCard.js │ │ ├── newCard.json │ │ ├── newCard.wxml │ │ └── newCard.wxss │ └── webview/ │ ├── webview.js │ └── webview.wxml └── utils/ └── util.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ root = true [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = false ================================================ FILE: .gitignore ================================================ project.config.json ================================================ FILE: LICENSE ================================================ The GNU General Public License, Version 2, June 1991 (GPLv2) ============================================================ > Copyright (C) 1989, 1991 Free Software Foundation, Inc. > 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble -------- The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. Terms And Conditions For Copying, Distribution And Modification --------------------------------------------------------------- **0.** This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. **1.** You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. **2.** You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: * **a)** You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. * **b)** You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. * **c)** If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. **3.** You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: * **a)** Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, * **b)** Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, * **c)** Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. **4.** You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. **5.** You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. **6.** Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. **7.** If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. **8.** If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. **9.** The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. **10.** If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. No Warranty ----------- **11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. **12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. ================================================ FILE: README.md ================================================ # 套餐助手 ### 手机套餐对比选购小程序 套餐助手是一个帮你在众多互联网套餐中选择最适合的套餐的小程序。 ## 赞助商
多态
## 立即体验 ![套餐助手小程序码](https://planmaster.prototype.im/minicode.jpg?fix) ## 截图 ## 开发使用说明 1. 若未安装微信开发中者工具需先安装微信开发者工具。 2. Clone 项目,使用微信开发者工具新建项目,选择项目目录即可。 ## 目录结构 ``` . ├── app.js // 在 onLaunch 时做一些统计相关的工作 ├── components │ └── sponsor // 广告组件,每次 onShow 时显示下一个广告 ├── pages │ ├── ad // 广告的 webview,广告的打开类型为 webview 时跳到该页面 │ ├── changePlan // 修改套餐页 │ ├── detail // 套餐详情页 │ ├── feedback // 反馈页面 │ ├── index // 首页,费用计算及套餐推荐,推荐套餐按费用升序排列 │ ├── newCard // 办理新卡的页面 │ └── webview // 一个通用的 webview,其他网页都跳到这个页面 ├── static │ └── images └── utils └── util.js // 工具函数,计算套餐的函数放在这里 ``` ## 项目介绍 该小程序可以通过设置每月通话时间、流量等自动计算各种互联网套餐所需的费用并按照升序排列,从而帮助用户选择出最适合自己的套餐。 该小程序有很多特色,比如加了很多漂亮的广告,这些广告不仅简洁漂亮,还支持多种打开方式,如跳转到另一个小程序,打开一个网页,甚至往剪贴板中写入一些内容。 除此之外,得益于[多态](https://www.duotai.net/?utm_source=planmaster&utm_medium=web&utm_campaign=planmaster-github)提供的表单功能,我们收集到了很多有用的用户反馈,从而帮助我们不断改进完善,也使得我们可以及时纠正套餐信息中存在的错误。 ## 许可协议 套餐助手小程序以附加禁止竞业限制的 GPLv2 许可证开放源代码。 本项目的授权协议禁止您使用本项目源码来开发和发布与套餐助手业务相同或相近的小程序(手机套餐对比推荐)。 ================================================ FILE: app.js ================================================ App({ onLaunch: function (opts) { if (opts.referrerInfo && opts.referrerInfo.extraData && opts.referrerInfo.extraData.from) { wx.reportAnalytics('adclick', { from: opts.referrerInfo.extraData.from, }) } wx.setStorage({ key: 'showTime', data: null, }) }, getAds: function (cb) { wx.request({ url: 'https://planmaster.prototype.im/ads.json', success: res => { const { showAd, ads } = res.data let showTime = Number(wx.getStorageSync('showTime')) || 0 if (showAd) { wx.setStorage({ key: 'showTime', data: showTime + 1 }) } const adData = { showAd: showAd, ads: ads, ad: ads[showTime % ads.length], } typeof cb === 'function' && cb(adData) } }) }, }) ================================================ FILE: app.json ================================================ { "pages":[ "pages/index/index", "pages/detail/detail", "pages/newCard/newCard", "pages/changePlan/changePlan", "pages/feedback/feedback", "pages/webview/webview", "pages/ad/ad" ], "window":{ "backgroundColor": "#F6F6F6", "backgroundTextStyle":"light", "navigationBarBackgroundColor": "#F6F6F6", "navigationBarTitleText": "套餐助手", "navigationBarTextStyle":"black" } } ================================================ FILE: app.wxss ================================================ page { background: #F6F6F6; } button { margin: 15px; } .btn-group { display: flex; justify-content: space-between; width: 100%; } .btn-group .btn:first-child { margin-right: 0; } .btn { flex-grow: 1; } .btn[type="primary"] { color: #FFF; background: #1ABCFE; } .btn[type="default"] { color: #FFF; background: #66C53A; } .input-value { display: inline-block; padding: 0 6px; border: 1px solid #CCCCCC; border-radius: 4px; max-width: 3.5em; font-size: 16px; text-align: center; } .no-padding { box-shadow: none !important; padding: 0 !important; margin: 20px 0 !important; } .footer { display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 25px; } .footer-image image { height: 32px; width: 158px; } .footer-text { padding-top: 10px; font-size: 14px; color: #A2A2A2; } ================================================ FILE: components/sponsor/sponsor.js ================================================ Component({ properties: { // 这里定义了innerText属性,属性值可以在组件使用时指定 ad: { type: Object, value: {}, }, show: { type: Boolean, value: false, } }, data: { }, methods: { setSopnsorImageHeight: function (e) { try { const { windowWidth } = wx.getSystemInfoSync() this.setData({ sopnsorImageHeight: (windowWidth - 30) / 3, }) } catch (error) { console.error(error) } }, goAd: function (e) { const { ad } = this.data const { openType } = e.currentTarget.dataset if (openType === 'mina') { wx.navigateToMiniProgram({ appId: ad.appId, path: ad.url, extraData: { from: 'planmaster', }, success(res) { } }) } if (openType === 'webview') { wx.navigateTo({ url: `/pages/ad/ad?url=${ad.url}` }) } if (openType === 'clipboard') { const { text, modal: { title, content } } = ad.data wx.setClipboardData({ data: text, success: function(res) { wx.showModal({ title: title, content: content, showCancel: false, }) } }) } }, } }) ================================================ FILE: components/sponsor/sponsor.json ================================================ { "component": true } ================================================ FILE: components/sponsor/sponsor.wxml ================================================ ================================================ FILE: components/sponsor/sponsor.wxss ================================================ .sponsor { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 15px; margin: 15px 0; font-size: 18px; border-radius: 8px; background: #FFF; box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); } .sponsor-row { display: flex; justify-content: space-between; align-items: flex-end; width: 100%; } .sponsor-row + .sponsor-row { margin-top: 10px; } .sponsor-column { display: flex; flex-direction: column; justify-content: center; align-items: space-between; align-self: stretch; flex-grow: 1; } .sponsor-img-box { flex-grow: 0; margin-right: 10px; } .sponsor-img { height: 60px; width: 50px; } .sponsor-title { font-size: 16px; } .sponsor-subtitle { font-size: 14px; color: #666666; } .sponsor-picture { width: 100%; border-radius: 6px; } .sponsor-prompt { min-width: 2em; padding: 1px 4px; text-align: center; font-size: 12px; color: #999; border: 1px solid #CCC; border-radius: 4px; } ================================================ FILE: pages/ad/ad.js ================================================ const app = getApp() Page({ data: { }, onLoad: function (q) { this.setData({ url: q.url, }) }, onShareAppMessage: function (res) { return { title: '套餐助手', path: '/pages/ad/ad?url=' + this.data.url, } }, }) ================================================ FILE: pages/ad/ad.wxml ================================================ ================================================ FILE: pages/changePlan/changePlan.js ================================================ const app = getApp() const serviceNumbers = { '中国联通': '10010', '中国电信': '10000', '中国移动': '10086', } Page({ data: { serviceNumbers: serviceNumbers, }, onLoad: function (q) { this.setData({ plan: JSON.parse(q.plan), }) }, onShow: function () { app.getAds(data => this.setData(data)) }, goChangePlanNow: function () { wx.makePhoneCall({ phoneNumber: serviceNumbers[this.data.plan.operator] }) }, }) ================================================ FILE: pages/changePlan/changePlan.json ================================================ { "navigationBarTitleText": "修改套餐", "usingComponents": { "sponsor": "/components/sponsor/sponsor" } } ================================================ FILE: pages/changePlan/changePlan.wxml ================================================ 如何将套餐修改为{{plan.cardName}}? 要将套餐改为「{{plan.cardName}}」您可直接致电{{serviceNumbers[plan.operator]}},转人工服务,请求客服帮您办理。需要注意的是老用户转套餐将不能享受新用户优惠,但是套餐中包含的免流等特权可以正常享受。 若客服表示无法办理或需要去营业厅办理,可用请求客服记一个需要回访的投诉,通常不久就会接到回访电话,这时一般就可以成功办理了。 ================================================ FILE: pages/changePlan/changePlan.wxss ================================================ .block { margin: 20px; } .title { margin: 15px; text-align: center; font-size: 24px; } button { margin: 15px 0; } ================================================ FILE: pages/detail/detail.js ================================================ const { computeFee } = require('../../utils/util') const app = getApp() Page({ data: { }, onLoad: function (q) { let plan = JSON.parse(q.plan) const call = Number(q.call) const inProvinceTraffic = Number(q.inProvinceTraffic) const nationalTraffic = Number(q.nationalTraffic) plan.price.costEstimate = computeFee(plan.price, call, inProvinceTraffic, nationalTraffic) app.getAds(data => this.setData(data)) this.setData({ plan: plan, call: call, inProvinceTraffic: inProvinceTraffic, nationalTraffic: nationalTraffic, }) }, onShareAppMessage: function (res) { const { plan, call, inProvinceTraffic, nationalTraffic } = this.data return { title: plan.partner + plan.cardName, path: '/pages/detail/detail?plan=' + JSON.stringify(plan) + '&call=' + call + '&inProvinceTraffic=' + inProvinceTraffic + '&nationalTraffic=' + nationalTraffic, } }, computeFee: function () { let { plan, call, inProvinceTraffic, nationalTraffic } = this.data plan.price.costEstimate = computeFee(plan.price, call, inProvinceTraffic, nationalTraffic) this.setData({ plan: plan, }) }, callInputChange: function (e) { let call = Math.ceil(e.detail.value.match(/\d+(?:\.\d+)?/)) this.setData({ call: call < 0 ? 0 : call }) this.computeFee() }, inProvinceTrafficInputChange: function (e) { let traffic = Number(e.detail.value.match(/\d+(?:\.\d+)?/)).toFixed(3) this.setData({ inProvinceTraffic: traffic < 0 ? 0 : Number(traffic), }) this.computeFee() }, nationalTrafficInputChange: function (e) { let traffic = Number(e.detail.value.match(/\d+(?:\.\d+)?/)).toFixed(3) this.setData({ nationalTraffic: traffic < 0 ? 0 : Number(traffic), }) this.computeFee() }, goChangePlan: function () { wx.navigateTo({ url: `/pages/changePlan/changePlan?plan=${JSON.stringify(this.data.plan)}` }) }, goApplyNew: function () { wx.navigateTo({ url: `/pages/newCard/newCard?plan=${JSON.stringify(this.data.plan)}` }) }, goFeedback: function () { wx.navigateTo({ url: `/pages/feedback/feedback?plan=${JSON.stringify(this.data.plan)}` }) }, goPrototype: function () { wx.navigateTo({ url: `/pages/webview/webview?url=https://prototype.im/` }) }, }) ================================================ FILE: pages/detail/detail.json ================================================ { "navigationBarTitleText": "套餐详情", "usingComponents": { "sponsor": "/components/sponsor/sponsor" } } ================================================ FILE: pages/detail/detail.wxml ================================================ var splitFee = function (fee) { if (typeof fee === 'string') { fee = fee.split('.') } else { fee = ['00', '00'] } return { feeBig: fee[0], feeSmall: fee[1] } } module.exports.splitFee = splitFee {{plan.cardName}} {{plan.price.condition}} {{plan.partner}} × {{plan.operator}} 月租{{plan.price.monthlyFee}} 套餐内通话 全国不限量 {{plan.price.callInplan}}分钟 套餐外通话 {{plan.price.callOutPlanPrice}}元每分钟 套餐内流量 全国不限量 省内不限量 省内{{plan.price.trafficInPlan.inProvince ? plan.price.trafficInPlan.inProvince : '无'}}{{plan.price.trafficInPlan.inProvince ? 'GB' : ''}} 全国{{plan.price.trafficInPlan.national ? plan.price.trafficInPlan.national : '无'}}{{plan.price.trafficInPlan.national ? 'GB' : ''}} 套餐外流量 省内 省内不限量 省内日租{{plan.price.trafficOutPlanPrice.inProvince.price}}元每天不限量 省内{{plan.price.trafficOutPlanPrice.inProvince.daily ? '日租' : '月租'}}{{plan.price.trafficOutPlanPrice.inProvince.price}}元每 {{plan.price.trafficOutPlanPrice.inProvince.quantity + ' GB'}} 全国 全国不限量 全国{{plan.price.trafficOutPlanPrice.national.daily ? '日租' : '月租'}}{{plan.price.trafficOutPlanPrice.national.price}}元每 {{plan.price.trafficOutPlanPrice.national.quantity +' GB'}} 特权 {{plan.privilege}} 费用预估 请填写您的预计使用量,我可以为您计算预计费用 通话时间 分钟 省内流量 GB 省外流量 GB 预计费用 {{m.splitFee(plan.price.costEstimate.totalFee).feeBig}}.{{m.splitFee(plan.price.costEstimate.totalFee).feeSmall}} 月租 {{m.splitFee(plan.price.costEstimate.monthlyFee).feeBig}}.{{m.splitFee(plan.price.costEstimate.monthlyFee).feeSmall}} 通话 {{m.splitFee(plan.price.costEstimate.callFee).feeBig}}.{{m.splitFee(plan.price.costEstimate.callFee).feeSmall}} 流量 {{m.splitFee(plan.price.costEstimate.trafficFee).feeBig}}.{{m.splitFee(plan.price.costEstimate.trafficFee).feeSmall}} 反馈问题 ================================================ FILE: pages/detail/detail.wxss ================================================ .block { margin: 18px; background: #FFF; font-size: 14px; box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); border-radius: 8px; } .block-no-style { background: none; box-shadow: none; border-radius: none; } .block-row { display: flex; justify-content: space-between; margin: 15px; padding: 0 10px; } .block-row:first-child { padding-top: 20px; } .block-row:last-child { padding-bottom: 20px; } .multi-row { align-items: flex-start; } .text-big { font-size: 16px; } .block-column { display: flex; justify-content: space-between; align-items: center; line-height: 28px; vertical-align: middle; } .block-divider { height: 2px; width: calc(100% - 40px); margin: 0 20px; background: rgba(0, 0, 0, 0.04); border-radius: 20px; } .row-icon { margin-right: 8px; height: 1em; width: 1.2em; } .row-inline-icon { margin: 0 8px; } .icon-offset { margin-left: calc(1.2em + 8px); } .input-unit { margin-left: 1em; color: #666; } .title { margin: 25px 18px; font-size: 20px; } .subtitle { margin-top: 15px; font-size: 14px; color: #666; } .block-title { display: flex; justify-content: space-between; align-items: center; width: 100%; font-size: 20px; } .block-subtitle { margin-left: 25px; text-align: right; font-size: 12px; color: #FF983C; } .block-value { margin: 0 6px; font-size: 20px; } .align-right { text-align: right; } .sub-fee { border-top: 1px solid #EEEEEE; background: #FAFAFA; border-radius: 8px; } .sub-fee .block-row { padding-top: 0; } .monthly-fee { margin: 0 6px; font-size: 24px; color: #29AE60; vertical-align: baseline; } .input-wrapper { display: flex; justify-content: space-between; align-items: center; width: 8em; } .privilege { font-size: 14px; color: #27AE60; } .fee-value { margin: 0 5px; color: #29AE60; } .fee-value-big { font-size: 20px; } ================================================ FILE: pages/feedback/feedback.js ================================================ const app = getApp() Page({ data: { }, onLoad: function (q) { try { let sysInfo = encodeURIComponent(JSON.stringify(wx.getSystemInfoSync())) let plan = q.plan && JSON.parse(q.plan) this.setData({ url: `https://i.duotai.co/forms/dkyqo?${sysInfo ? 'appVersion=' + sysInfo : ''}${plan ? '&plan=' + encodeURIComponent(plan.partner + plan.cardName) : ''}` }) } catch (error) { console.error(error) } }, }) ================================================ FILE: pages/feedback/feedback.json ================================================ { "navigationBarTitleText": "套餐助手反馈" } ================================================ FILE: pages/feedback/feedback.wxml ================================================ ================================================ FILE: pages/index/index.js ================================================ const { computeFee } = require('../../utils/util') const app = getApp() let plans const calls = [0, 50, 100, 200, 300, 500, 700, 1000, 1500, 2000, 2500, 3000] const traffics = [0, 0.01, 0.02, 0.05, 0.2, 0.5, 0.7, 1, 2, 3, 5, 10, 20, 50, 100, 200] const shareImage = 'https://planmaster.prototype.im/share_image.png' let shareImageDownloaded = false Page({ data: { call: calls[1], callSlider: 1, traffic: traffics[7], trafficSlider: 7, trafficPerDay: traffics[7] / 30, freeTraffic: false, outProvinceDay: 0, operators: [ { show: true, name: '联通', checked: true, img: '/static/images/unicom.svg', }, { show: true, name: '电信', checked: false, img: '/static/images/telecom.svg', }, { show: true, name: '移动', checked: false, img: '/static/images/cmcom.png', }, ], selectedOperators: ['中国联通'], plans: [ { "operator": "中国联通", "partner": "腾讯", "cardName": "大王卡", "guideUrl": "https://planmaster.prototype.im/tencent", "price": { "monthlyFee": 19, "trafficInPlan": { "national": 0, "inProvince": 0 }, "callInplan": 0, "callOutPlanPrice": 0.1, "trafficOutPlanPrice": { "national": { "daily": true, "price": 2, "quantity": 0.5 }, "inProvince": { "daily": true, "price": 1, "quantity": 0.5 } } }, "privilege": "腾讯视频、王者荣耀等腾讯系应用及游戏免流,斗鱼等直播免流", "description": "腾讯系应用及游戏免流,熊猫等直播免流" }, { "operator": "中国联通", "partner": "蚂蚁金服", "cardName": "大宝卡", "guideUrl": "https://planmaster.prototype.im/alipay", "price": { "monthlyFee": 36, "condition": "满一年或预存200", "trafficInPlan": { "national": 3, "inProvince": 0 }, "callInplan": 200, "callOutPlanPrice": 0.1, "trafficOutPlanPrice": { "national": { "daily": false, "price": 10, "quantity": 1 }, "inProvince": null } }, "privilege": "线下买单送流量。2017年11月起,全系每月+3元可享优酷视频免流(视频广告也免流,缓存下载不免流)", "description": "送流量,优酷视频免流" }, { "operator": "中国联通", "partner": "百度", "cardName": "小圣卡", "guideUrl": "https://planmaster.prototype.im/sheng", "price": { "monthlyFee": 9, "trafficInPlan": { "national": 0.1, "inProvince": 0 }, "callInplan": 0, "callOutPlanPrice": 0.1, "trafficOutPlanPrice": { "inProvince": { "daily": true, "price": 1, "quantity": 0.8 }, "national": { "daily": false, "price": 15, "quantity": 1 } } }, "privilege": "手机百度、百度贴吧、百度地图、爱奇艺、好看视频等APP免流量", "description": "百度系APP免流量" }, { "operator": "中国联通", "partner": "哔哩哔哩", "cardName": "33卡", "guideUrl": "https://planmaster.prototype.im/bilibili", "price": { "monthlyFee": 33, "condition": "满一年或预存200元", "trafficInPlan": { "national": 2, "inProvince": 0 }, "callInplan": 100, "callOutPlanPrice": 0.1, "trafficOutPlanPrice": { "national": { "daily": true, "price": 1, "quantity": 0.5 }, "inProvince": null } }, "privilege": "哔哩哔哩免流", "description": "哔哩哔哩免流" }, { "operator": "中国联通", "partner": "网易", "cardName": "大白金卡", "guideUrl": "https://planmaster.prototype.im/wangyi", "price": { "monthlyFee": 19, "trafficInPlan": { "national": 1, "inProvince": 0 }, "callInplan": 100, "callOutPlanPrice": 0.1, "trafficOutPlanPrice": { "inProvince": { "daily": true, "price": 1, "quantity": 0.8 }, "national": { "daily": true, "price": 2, "quantity": 0.8 } } }, "privilege": "网易系应用游戏全免流", "description": "网易系应用游戏全免流" }, ] }, onShow: function () { wx.request({ url: 'https://planmaster.prototype.im', success: res => { plans = typeof res.data === 'object' ? res.data : this.data.plans let { operators } = this.data operators = plans.some(p => p.operator === '中国移动') ? operators : operators.filter(o => o.name !== '移动') this.setData({ plans: plans, operators: operators, }) this.recommendPlan(plans) } }) app.getAds(data => this.setData(data)) }, onShareAppMessage: function (res) { return { title: '套餐助手', path: '/pages/index/index', } }, recommendPlan: function (plans) { const { call, traffic, outProvinceDay, selectedOperators } = this.data const inProvinceTraffic = traffic * (30 - outProvinceDay) / 30 const nationalTraffic = traffic * outProvinceDay / 30 let recommendedPlans = plans .filter(p => selectedOperators.includes(p.operator)) .map(plan => { plan.price.costEstimate = computeFee(plan.price, call, inProvinceTraffic, nationalTraffic) return plan }) .sort((a, b) => a.price.costEstimate.totalFee - b.price.costEstimate.totalFee) if (selectedOperators.includes('中国联通') && recommendedPlans[0] && recommendedPlans[0].price.costEstimate.totalFee > 150) { const icecream = recommendedPlans.find(p => p.cardName === '芝麻冰激凌') recommendedPlans = recommendedPlans.filter(p => p.cardName !== '芝麻冰激凌') recommendedPlans.unshift(icecream) } this.setData({ recommendedGreatPlans: recommendedPlans.slice(0, 1), recommendedGoodPlans: recommendedPlans.slice(1, 3), recommendedOtherPlans: recommendedPlans.slice(3), }) }, callSliderChange: function (e) { const callSlider = Number(e.detail.value) this.setData({ callSlider: callSlider, call: calls[Number(e.detail.value)], }) this.recommendPlan(plans) }, callSliderChaning: function (e) { this.setData({ call: calls[Number(e.detail.value)], }) }, callInputChange: function (e) { let call = Math.ceil(e.detail.value.match(/\d+(?:\.\d+)?/)) this.setData({ call: call < 0 ? 0 : call }) this.recommendPlan(plans) }, trafficSliderChange: function (e) { const trafficSlider = Number(e.detail.value) this.setData({ trafficSlider: trafficSlider, traffic: traffics[Number(e.detail.value)], trafficPerDay: traffics[Number(e.detail.value)] / 30, }) this.recommendPlan(plans) }, trafficSliderChanging: function (e) { this.setData({ traffic: traffics[Number(e.detail.value)], }) }, trafficInputChange: function (e) { let traffic = Number(e.detail.value.match(/\d+(?:\.\d+)?/)).toFixed(3) this.setData({ traffic: traffic < 0 ? 0 : Number(traffic), }) this.recommendPlan(plans) }, outProvinceDaySliderChange: function (e) { this.setData({ outProvinceDay: Number(e.detail.value), }) this.recommendPlan(plans) }, outProvinceDaySliderChanging: function (e) { this.setData({ outProvinceDay: Number(e.detail.value), }) }, outProvinceDayInputChange: function (e) { let outProvinceDay = Number(e.detail.value.match(/\d+(?:\.\d+)?/)) outProvinceDay = outProvinceDay > 30 ? 30 : outProvinceDay < 0 ? 0 : outProvinceDay this.setData({ outProvinceDay: outProvinceDay, }) this.recommendPlan(plans) }, goOutChange: function (e) { this.setData({ goOutFrequently: e.detail.value === 'yes', }) }, freeTrafficChange: function (e) { this.setData({ freeTraffic: e.detail.value === 'yes', }) this.recommendPlan(plans) }, applyModeChange: function (e) { this.setData({ applyMode: e.detail.value, }) this.recommendPlan(plans) }, onOperatorChange: function (e) { const { index, checked } = e.currentTarget.dataset let { operators, selectedOperators } = this.data operators[index].checked = !checked selectedOperators = operators.filter(o => o.checked).map(o => '中国' + o.name) this.setData({ operators: operators, selectedOperators: selectedOperators, }) this.recommendPlan(plans) }, previewShareImage: function () { wx.previewImage({ current: shareImage, urls: [shareImage], }) }, getShareImage: function () { const showSuccessModal = () => { wx.showModal({ title: '分享图片保存成功', content: '分享图片已经保存到相册,请在朋友圈点击选择相册中的图片然后进行分享。', }) } const showFailModal = () => { wx.showModal({ title: '保存失败', content: '请尝试手动保存。', showCancel: false, success: () => { this.previewShareImage() } }) } const saveImage = () => { wx.showLoading() wx.downloadFile({ header: { 'Accept': 'image/*' }, url: shareImage, success: res => { console.log('download success') wx.hideLoading() if (res.statusCode !== 200) { showFailModal() return } wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success: () => { shareImageDownloaded = true showSuccessModal() }, fail: res => { showFailModal() }, complete: () => { } }) }, }) } if (shareImageDownloaded) { showSuccessModal() return } wx.getSetting({ success: (res) => { if (res.authSetting["scope.writePhotosAlbum"] === undefined) { wx.showModal({ title: '需要图片保存权限', content: '我们需要保存图片到系统相册的权限,以保存分享图片,请在弹出的授权框中选择允许。', showCancel: false, success: () => { saveImage() } }) } else { saveImage() } } }) }, goDetail: function (e) { const { call, traffic, outProvinceDay, recommendedGreatPlans, recommendedGoodPlans, recommendedOtherPlans } = this.data const inProvinceTraffic = traffic * (30 - outProvinceDay) / 30 const nationalTraffic = traffic * outProvinceDay / 30 const { index, type } = e.currentTarget.dataset let plans switch (type) { case 'great': plans =recommendedGreatPlans break case 'good': plans =recommendedGoodPlans break case 'other': plans =recommendedOtherPlans break default: break } const plan = plans[index] if (plan.operator === '中国移动') { wx.navigateTo({ url: '/pages/webview/webview?url=' + plan.guideUrl, }) } else { wx.navigateTo({ url: '/pages/detail/detail?plan=' + JSON.stringify(plan) + '&call=' + call + '&inProvinceTraffic=' + inProvinceTraffic + '&nationalTraffic=' + nationalTraffic }) } }, goFeedback: function () { wx.navigateTo({ url: `/pages/feedback/feedback` }) }, goPrototype: function () { wx.navigateTo({ url: `/pages/webview/webview?url=https://prototype.im/` }) }, }) ================================================ FILE: pages/index/index.json ================================================ { "usingComponents": { "sponsor": "/components/sponsor/sponsor" } } ================================================ FILE: pages/index/index.wxml ================================================ var splitFee = function (fee) { if (typeof fee === 'string') { fee = fee.split('.') } else { fee = ['00', '00'] } return { feeBig: fee[0], feeSmall: fee[1] } } module.exports.splitFee = splitFee; 使用量设置 您一般每个月使用多少通话和流量? 每月平均通话时间 分钟 每月平均流量使用 GB 每月在省外的时间 推荐套餐 以下是我根据您选择的使用量为您推荐的套餐 {{item.name}} {{item.cardName}} {{item.partner}} {{item.price.condition}} {{m.splitFee(item.price.costEstimate.totalFee).feeBig}}.{{m.splitFee(item.price.costEstimate.totalFee).feeSmall}}元/月 {{item.description}} {{item.cardName}} {{item.partner}} {{item.price.condition}} {{m.splitFee(item.price.costEstimate.totalFee).feeBig}}.{{m.splitFee(item.price.costEstimate.totalFee).feeSmall}}元/月 {{item.description}} {{item.cardName}} {{item.partner}} {{item.price.condition}} {{m.splitFee(item.price.costEstimate.totalFee).feeBig}}.{{m.splitFee(item.price.costEstimate.totalFee).feeSmall}}元/月 {{item.description}} 反馈问题 ================================================ FILE: pages/index/index.wxss ================================================ page { min-height: 100%; } .container { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-between; box-sizing: border-box; } .block { padding: 15px; width: 100%; box-sizing: border-box; } .block-title { font-size: 20px; margin-bottom: 30px; } .block-subtitle { margin: 15px 0; font-size: 14px; color: #666; } .block-item { position: relative; display: flex; justify-content: space-between; align-items: center; margin: 15px 0; padding: 15px; font-size: 18px; border-radius: 8px; background: #FFF; box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); } .block-item:last-child { margin-bottom: 0; } .block-item.column { flex-direction: column; } .item-row { display: flex; justify-content: space-between; align-items: center; width: 100%; } .item-row + .item-row { margin-top: 10px; } .item-column { display: flex; flex-direction: column; justify-content: space-between; align-self: stretch; flex-grow: 1; } .item-title { font-size: 16px; } .item-title-icon { height: 1.2em; width: 1.2em; margin-right: 10px; vertical-align: middle; } .checkbox-group { display: flex; flex-direction: column; } .checkbox { margin: 10px; } .radio-group { display: flex; justify-content: space-around; width: 70%; margin: 15px auto; } .slider-box { flex-grow: 1; } .slider { margin-left: 10px; margin-right: 20px; flex-grow: 1; } .slider-value { display: flex; justify-content: space-around; align-items: center; margin: 15px auto; width: 70%; } .input-unit { text-align: right; font-size: 14px; color: #999; } .operator { display: flex; justify-content: space-between; } .operator-item { display: flex; justify-content: space-between; align-items: center; flex-grow: 1; margin-bottom: 15px; padding: 8px; font-size: 12px; line-height: 16px; border-radius: 8px; background: #FFF; box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); } .operator-item + .operator-item { margin-left: 10px; } .operator-text { vertical-align: middle; } .operator-icon { height: 1em; width: 1.2em; vertical-align: middle; } .operator-icon-inline { margin-right: 0.4em; } .operator-icon-big { height: 1.5em; width: 1.5em; } @media (min-device-width: 375px) { .operator-item { display: flex; justify-content: space-between; align-items: center; flex-grow: 1; margin-bottom: 15px; padding: 10px; font-size: 14px; line-height: 16px; border-radius: 8px; background: #FFF; box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.1); } .operator-item + .operator-item { margin-left: 15px; } } .plan-rank-icon { margin-right: 10px; height: 1.5em; width: 1.2em; vertical-align: middle; } .plan-name text { line-height: 1.5em; vertical-align: middle; } .plan-fee { font-size: 14px; text-align: right; } .normal-fee { margin-bottom: 5px; } .condition { max-width: 15em; font-size: 12px; color: #FF983C; } .discounted-fee { max-width: 15em; font-size: 12px; color: #60D390; } .fee-value { margin: 0 5px; color: #FF983C; } .fee-value-big { font-size: 20px; } .fee-value.recommanded { color: #29AE60; } .plan-partner-name { margin-top: 10px; font-size: 12px; color: #666; } .share-btn { margin: 0; margin-top: 10px; width: calc(50% - 15px); line-height: 2.4em; font-size: 16px; } .share-btn:not(:first-child) { margin-left: 15px; } ================================================ FILE: pages/newCard/newCard.js ================================================ const app = getApp() Page({ data: { }, onLoad: function (q) { this.setData({ plan: JSON.parse(q.plan), }) }, }) ================================================ FILE: pages/newCard/newCard.json ================================================ { "navigationBarTitleText": "办理新卡" } ================================================ FILE: pages/newCard/newCard.wxml ================================================ ================================================ FILE: pages/newCard/newCard.wxss ================================================ .title { text-align: center; font-size: 24px; } ================================================ FILE: pages/webview/webview.js ================================================ const app = getApp() Page({ data: { }, onLoad: function (q) { this.setData({ url: q.url, }) }, onShareAppMessage: function (res) { return { title: '套餐助手', path: '/pages/webview/webview?url=' + this.data.url, } }, }) ================================================ FILE: pages/webview/webview.wxml ================================================ ================================================ FILE: utils/util.js ================================================ const formatTime = date => { const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') } const formatNumber = n => { n = n.toString() return n[1] ? n : '0' + n } const computeFee = (price, call, inProvinceTraffic, nationalTraffic) => { const overCall = call - price.callInplan <= 0 ? 0 : call - price.callInplan let trafficPerDay = (inProvinceTraffic + nationalTraffic) / 30 let noInProvinceTrafficDays = 0 let noNationalTrafficDays = 0 let noTrafficDays = 30 - (price.trafficInPlan.inProvince + price.trafficInPlan.national) / trafficPerDay noTrafficDays = noTrafficDays >= 0 ? noTrafficDays : 0 if (trafficPerDay > 0) { noInProvinceTrafficDays = noTrafficDays * (inProvinceTraffic / (inProvinceTraffic + nationalTraffic)) > 0 ? noTrafficDays * (inProvinceTraffic / (inProvinceTraffic + nationalTraffic)) : 0 noNationalTrafficDays = noTrafficDays * (nationalTraffic / (inProvinceTraffic + nationalTraffic)) > 0 ? noTrafficDays * (nationalTraffic / (inProvinceTraffic + nationalTraffic)) : 0 } if (price.trafficInPlan.inProvince === 0) { inProvinceTraffic = inProvinceTraffic - price.trafficInPlan.national * inProvinceTraffic / (inProvinceTraffic + nationalTraffic) nationalTraffic = nationalTraffic - price.trafficInPlan.national * nationalTraffic / (inProvinceTraffic + nationalTraffic) } else { inProvinceTraffic = inProvinceTraffic - price.trafficInPlan.inProvince nationalTraffic = nationalTraffic - price.trafficInPlan.national } inProvinceTraffic = inProvinceTraffic >= 0 ? inProvinceTraffic : 0 nationalTraffic = nationalTraffic >= 0 ? nationalTraffic : 0 if (!price.trafficOutPlanPrice.inProvince) { nationalTraffic = inProvinceTraffic + nationalTraffic noNationalTrafficDays = noNationalTrafficDays + noInProvinceTrafficDays inProvinceTraffic = 0 noInProvinceTrafficDays = 0 } let fee = price.monthlyFee let callFee = overCall * price.callOutPlanPrice let trafficFee = 0 let inProvinceFee = 0 let nationalFee = 0 const { inProvince, national, daily } = price.trafficOutPlanPrice if (inProvinceTraffic + nationalTraffic > 0) { if (inProvince && national) { if (inProvince.daily) { inProvinceFee = Math.ceil(trafficPerDay / inProvince.quantity) * inProvince.price * noInProvinceTrafficDays } else { inProvinceFee = Math.ceil(inProvinceTraffic / inProvince.quantity) * inProvince.price } if (national.daily) { nationalFee = Math.ceil(trafficPerDay / national.quantity) * national.price * noNationalTrafficDays } else { nationalFee = Math.ceil(nationalTraffic / national.quantity) * national.price } } else if (national) { if (national.daily) { nationalFee = Math.ceil(trafficPerDay / national.quantity) * national.price * noNationalTrafficDays } else { nationalFee = Math.ceil(nationalTraffic / national.quantity) * national.price } } } trafficFee = nationalFee + inProvinceFee return { totalFee: (fee + callFee + trafficFee).toFixed(2), monthlyFee: price.monthlyFee.toFixed(2), callFee: callFee.toFixed(2), inProvinceFee: inProvinceFee.toFixed(2), nationalFee: nationalFee.toFixed(2), trafficFee: trafficFee.toFixed(2), } } module.exports = { formatTime: formatTime, computeFee: computeFee, }