App.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <div id="app">
  3. <div class="vip-container">
  4. <div class="vip-info">
  5. <div class="title">加入AI降临派VIP</div>
  6. <div class="desc">和我们一起探索AI的技术边界</div>
  7. <!-- <div class="date">
  8. <span class="oplist" @click="gotoOrderList" v-if="!isIOS">订单记录></span>
  9. <span v-if="isVIP">会员有效期至: {{ expireTime ? dateFormat(expireTime, 'yyyy-MM-dd') : '-'}}</span>
  10. </div> -->
  11. </div>
  12. <div>{{chatToken}}</div>
  13. <div class="vip-info vip-rights">
  14. <div class="title-view">
  15. <div class="tabitem" :class="{active: ctype == 1}" @click="ctype = 1">
  16. VIP会员权益
  17. </div>
  18. <div class="tabitem" :class="{active: ctype == 2}" @click="ctype = 2">
  19. AI能量包
  20. </div>
  21. </div>
  22. <div class="recharge-types">
  23. <div class="type-item" v-for="(item, index) in typelist" :class="{active: curIndex === index}"
  24. :key="index" @click="changeChargeType(index)">
  25. <div class="p1">{{ item.typename }}</div>
  26. <div class="p-now">{{ item.price }}</div>
  27. <div class="p-op">{{ item.op }}</div>
  28. <div class="p2" :class="{needScale: ctype == 1}">{{ item.desc }}</div>
  29. </div>
  30. </div>
  31. <div class="list" v-if="ctype == 1">
  32. <div class="list-item" v-for="(item, index) in list" :key="index">
  33. {{ item }}
  34. </div>
  35. </div>
  36. <div class="list" v-if="ctype == 2">
  37. <div class="list-item" v-for="(item, index) in list2" :key="index">
  38. {{ item }}
  39. </div>
  40. </div>
  41. </div>
  42. <div class="pay-view">
  43. <div class="pay-btn" @click="handlePay">
  44. 支付
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import axios from 'axios'
  52. import { queryToObj } from './utils/index.js'
  53. const PAY_TYPE = {
  54. MONTHLY: 'MONTHLY', //包月
  55. SEASONALLY: 'SEASONALLY', //包季;
  56. YEARLY: 'YEARLY' ,// 包年
  57. S_PLUS: 'S_PLUS',
  58. M_PLUS: 'M_PLUS',
  59. L_PLUS: 'L_PLUS'
  60. }
  61. const baseurl = 'https://api.aibaidu.com.cn/'
  62. let chatSeq = 1000000
  63. export default {
  64. name: 'App',
  65. data() {
  66. return {
  67. chatToken: '',
  68. ctype: 1,
  69. list2: [
  70. '1、购买AI能量包立刻获得算力。',
  71. '2、多个AI能量包可重复可叠加购买,算力永不过期。'
  72. ],
  73. curIndex: 0,
  74. vipTypes: [
  75. { type: PAY_TYPE.MONTHLY, typename: '1个月VIP', op: '¥30', desc: '给程序员买杯咖啡'},
  76. { type: PAY_TYPE.SEASONALLY, typename: '3个月VIP', op: '¥90', desc: '请程序员喝个小酒'},
  77. { type: PAY_TYPE.YEARLY, typename: '12个月VIP', op: '¥360', desc: '请程序员吃顿大餐'}
  78. ],
  79. timesTypes: [
  80. { type: PAY_TYPE.S_PLUS, typename: '小能量包', op: '¥15', desc: '200点算力'},
  81. { type: PAY_TYPE.M_PLUS, typename: '中能量包', op: '¥30', desc: '400点算力'},
  82. { type: PAY_TYPE.L_PLUS, typename: '大能量包', op: '¥45', desc: '600点算力'}
  83. ],
  84. orderList: [],
  85. page: 1,
  86. }
  87. },
  88. created() {
  89. const search = window.location.search
  90. const obj = queryToObj(search.substring(1))
  91. this.chatToken = obj.chatToken
  92. this.getProducts()
  93. },
  94. computed: {
  95. typelist() {
  96. if (this.ctype == 1) {
  97. return this.vipTypes
  98. } else if (this.ctype == 2) {
  99. return this.timesTypes
  100. } else {
  101. return []
  102. }
  103. },
  104. list() {
  105. const arr1 = [300, 1000, 5000]
  106. const arr2 = [10, 30, 120]
  107. return [
  108. `1、立即获得${arr1[this.curIndex]}点算力。`,
  109. `2、立即获得${arr2[this.curIndex]}次AI绘画插队权益。`,
  110. '3、每日签到领取20点算力,每月最多可领600点算力。',
  111. '4、每日签到领取2次AI绘画插队权益,每月最多可领60次绘画插队权益。',
  112. '5、在高峰时段获得AI智能问答优先回复,使用更顺畅。'
  113. ]
  114. }
  115. },
  116. methods: {
  117. async handlePay() {
  118. const type = this.typelist[this.curIndex].id
  119. const {data: res} = await axios({
  120. url: baseurl + 'wx-mp/preOrder',
  121. method: 'POST',
  122. headers: {
  123. 'content-type': 'application/x-www-form-urlencoded',
  124. 'chat-token': this.chatToken,
  125. 'chat-seq': chatSeq++
  126. },
  127. data: {
  128. type: type
  129. }
  130. })
  131. if (res.code === 0) {
  132. // eslint-disable-next-line
  133. this.payObj = res.data
  134. if (typeof WeixinJSBridge == "undefined") {
  135. if (document.addEventListener) {
  136. document.addEventListener(
  137. "WeixinJSBridgeReady",
  138. this.onBridgeReady,
  139. false
  140. );
  141. } else if (document.attachEvent) {
  142. document.attachEvent("WeixinJSBridgeReady", this.onBridgeReady);
  143. document.attachEvent("onWeixinJSBridgeReady", this.onBridgeReady);
  144. }
  145. } else {
  146. this.onBridgeReady();
  147. }
  148. }
  149. },
  150. onBridgeReady() {
  151. const that = this
  152. // eslint-disable-next-line
  153. WeixinJSBridge.invoke(
  154. "getBrandWCPayRequest",
  155. {
  156. appId: this.payObj.appId, //公众号ID,由商户传入
  157. timeStamp: this.payObj.timeStamp, //时间戳,自1970年以来的秒数
  158. nonceStr: this.payObj.nonceStr, //随机串
  159. package: this.payObj.packageVal,
  160. signType: this.payObj.signType, //微信签名方式:
  161. paySign: this.payObj.paySign, //微信签名
  162. },
  163. function (res) {
  164. console.log('支付结果:', res)
  165. if (res.err_msg == "get_brand_wcpay_request:ok") {
  166. // 使用以上方式判断前端返回,微信团队郑重提示:
  167. //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  168. alert("支付成功");
  169. }
  170. that.closePage();
  171. }
  172. );
  173. },
  174. changeChargeType(index) {
  175. this.curIndex = index
  176. },
  177. async getProducts() {
  178. const {data: res} = await axios({
  179. url: baseurl + 'user/products',
  180. method: 'GET',
  181. headers: {
  182. 'content-type': 'application/x-www-form-urlencoded',
  183. 'chat-token': this.chatToken,
  184. 'chat-seq': chatSeq++
  185. }
  186. })
  187. if (res.code === 0) {
  188. const vips = []
  189. res.data.vip.map((m, index) => {
  190. const price = `¥${parseFloat((m.amount / 100).toFixed(2))}`
  191. vips[index] = {...this.vipTypes[index], ...m, price}
  192. })
  193. this.vipTypes = vips;
  194. const plus = []
  195. res.data.plus.map((m, index) => {
  196. const price = `¥${parseFloat((m.amount / 100).toFixed(2))}`
  197. plus[index] = {...this.timesTypes[index], ...m, price}
  198. })
  199. this.timesTypes = plus
  200. }
  201. },
  202. closePage() {
  203. var userAgent = navigator.userAgent;
  204. if (
  205. userAgent.indexOf("Firefox") != -1 ||
  206. userAgent.indexOf("Chrome") != -1
  207. ) {
  208. // Firefox或Chrome中关闭
  209. window.location.href = "about:blank";
  210. } else {
  211. window.opener = null;
  212. window.open("", "_self");
  213. window.close();
  214. }
  215. // eslint-disable-next-line
  216. if (WeixinJSBridge) {
  217. // 微信中关闭
  218. // eslint-disable-next-line
  219. wx.closeWindow();
  220. }
  221. }
  222. }
  223. }
  224. </script>
  225. <style lang="less" scoped>
  226. // @import url('./assets/mixin.less');
  227. .combtn(@fs: 28rpx, @lineHeight: 60rpx) {
  228. font-size: @fs;
  229. line-height: @lineHeight;
  230. background-color: @mainColor;
  231. border: none;
  232. color: #FFF;
  233. text-align: center;
  234. border-radius: 8rpx;
  235. &:active {
  236. background-color: lighten(@mainColor, 5%);
  237. }
  238. }
  239. #app {
  240. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  241. -webkit-font-smoothing: antialiased;
  242. -moz-osx-font-smoothing: grayscale;
  243. text-align: left;
  244. color: #EFEFEF;
  245. /* margin-top: 60px; */
  246. background-color: #33373f;
  247. height: 100vh;
  248. }
  249. .vip-container {
  250. padding: 20px;
  251. background-color: @mainBg;
  252. height: 100%;
  253. color: #EDEDED;
  254. .iosview {
  255. margin-top: 15px;
  256. color: @fontColor;
  257. }
  258. .btnview {
  259. margin-top: 150px;
  260. padding: 30px;
  261. .subbtn {
  262. .combtn(16px, 50px);
  263. }
  264. }
  265. .vip-info {
  266. padding: 10px 15px;
  267. background-color: lighten(@mainBg, 10%);
  268. border-radius: 6px;
  269. .title {
  270. color: @mainColor;
  271. font-size: 18px;
  272. font-weight: 600;
  273. }
  274. .desc {
  275. font-size: 14px;
  276. padding-top: 2px;
  277. }
  278. .date {
  279. padding-top: 12px;
  280. display: flex;
  281. justify-content: space-between;
  282. .oplist {
  283. color: @mainColor;
  284. }
  285. }
  286. }
  287. .vip-rights {
  288. margin-top: 15px;
  289. padding-bottom: 20px;
  290. height: 400px;
  291. box-sizing: border-box;
  292. .title-view {
  293. display: flex;
  294. .tabitem {
  295. line-height: 36px;
  296. flex: 1;
  297. color: @fontColor;
  298. font-size: 16px;
  299. font-weight: 600;
  300. text-align: center;
  301. position: relative;
  302. &.active {
  303. color: @mainColor;
  304. }
  305. &:last-child::after {
  306. content: "";
  307. height: 14px;
  308. left: 0;
  309. top: 11px;
  310. width: 1px;
  311. background-color: #EDEDED;
  312. position: absolute;
  313. }
  314. }
  315. }
  316. .list {
  317. padding: 10px 0;
  318. .list-item {
  319. padding: 2px 0;
  320. }
  321. }
  322. .recharge-types {
  323. padding-top: 12px;
  324. display: flex;
  325. .type-item {
  326. flex: 1;
  327. border: 1px solid @mainColor;
  328. background-color: transparent;
  329. border-radius: 4px;
  330. text-align: center;
  331. font-size: 12px;
  332. padding: 10px 0;
  333. // font-weight: 600;
  334. &:not(:last-child) {
  335. margin-right: 10px;
  336. }
  337. &.active {
  338. color: #fff;
  339. background-color: #32715f;
  340. }
  341. .p1 {
  342. font-size: 14px;
  343. }
  344. .p-now {
  345. font-weight: 600;
  346. font-size: 24px;
  347. line-height: 50px;
  348. }
  349. .p-op {
  350. font-size: 14px;
  351. text-decoration: line-through;
  352. }
  353. .p2.needScale {
  354. line-height: 20px;
  355. transform: scale(0.85);
  356. word-break: keep-all;
  357. }
  358. }
  359. }
  360. }
  361. .pay-view {
  362. position: fixed;
  363. padding: 10px 0;
  364. bottom: 40px;
  365. left: 0;
  366. display: flex;
  367. flex-direction: column;
  368. justify-content: center;
  369. align-items: center;
  370. width: 100%;
  371. box-sizing: border-box;
  372. .pay-btn {
  373. width: 160px;
  374. line-height: 40px;
  375. text-align: center;
  376. background-color: @mainColor;
  377. border-radius: 4px;
  378. color: #fff;
  379. font-size: 16px;
  380. }
  381. .paydesc {
  382. text-align: center;
  383. font-size: 12px;
  384. padding: 5px 0;
  385. }
  386. }
  387. }
  388. </style>