index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <template>
  2. <v-container class="invite-user" fluid :class="`bg-${type}`">
  3. <activity-invite-user-box class="box1">
  4. <template #title>参与步骤</template>
  5. <v-img
  6. class="cybz-content"
  7. :src="returnContent ? returnContent.img : null"
  8. />
  9. <div class="cybz-content-text">
  10. <div class="cybz-content-text-item">分享好友</div>
  11. <div class="cybz-content-text-item">邀请购买云机</div>
  12. <div class="cybz-content-text-item">
  13. {{ returnContent ? returnContent.content : '' }}
  14. </div>
  15. </div>
  16. <v-btn class="share-button" rounded @click="share()">
  17. <template v-if="!($userAgent.isSzx || $userAgent.isSzxBrowser)"
  18. >复制链接</template
  19. >分享好友
  20. </v-btn>
  21. <!-- <button @click="share()">邀请</button> -->
  22. </activity-invite-user-box>
  23. <activity-invite-user-box class="ox box2">
  24. <template #title>收益明细</template>
  25. <div class="grid grid-cols-2 gap-x-4 gap-y-8">
  26. <div
  27. v-for="(item, index) in dataList"
  28. :key="index"
  29. :class="{
  30. 'col-span-2': index === 6,
  31. }"
  32. >
  33. <div class="label text-sm">
  34. <span>{{ item.label }}</span>
  35. </div>
  36. <div class="value text-2xl font-bold">
  37. <span>{{ item.value | formatNumber }}</span>
  38. </div>
  39. </div>
  40. </div>
  41. </activity-invite-user-box>
  42. <activity-invite-user-box v-if="type === 2" class="box3">
  43. <template #title>激活码明细</template>
  44. <div class="code-table">
  45. <div class="table-header">
  46. <table class="w-full">
  47. <colgroup>
  48. <col class="time-col" />
  49. <col class="code-col" />
  50. <col class="status-col" />
  51. </colgroup>
  52. <thead class="text-left text-sm whitespace-nowrap break-normal">
  53. <tr>
  54. <th class="">获得的时间</th>
  55. <th>激活码编号</th>
  56. <th class="">使用状态</th>
  57. </tr>
  58. </thead>
  59. </table>
  60. </div>
  61. <div class="table-body">
  62. <table class="w-full">
  63. <colgroup>
  64. <col class="time-col" />
  65. <col class="code-col" />
  66. <col class="status-col" />
  67. </colgroup>
  68. <tbody class="text-xs">
  69. <tr v-for="(item, index) in myActivationCode" :key="index">
  70. <td class="whitespace-nowrap break-normal">
  71. {{ item.createTime | formatDate('MM月DD日 HH:mm:ss') }}
  72. </td>
  73. <td class="whitespace-nowrap break-normal">
  74. <div class="flex">
  75. <span class="font-mono"
  76. >{{ item.activationCode | activationCodeMask }} </span
  77. ><span class="mx-1">|</span
  78. ><v-btn
  79. text
  80. small
  81. color="#991AD2"
  82. class="copy-btn"
  83. @click="copyCode(item)"
  84. >复制</v-btn
  85. >
  86. </div>
  87. </td>
  88. <td class="whitespace-nowrap break-normal text-right">
  89. <span v-if="item.activationUse" style="color: #dd1b0d"
  90. >已使用</span
  91. >
  92. <span v-else>未使用</span>
  93. </td>
  94. </tr>
  95. </tbody>
  96. </table>
  97. <div
  98. v-if="myActivationCode.length"
  99. v-intersect.quiet="codeLoadMoreIntersect"
  100. class="flex item-center justify-center"
  101. >
  102. <!-- <v-progress-circular indeterminate ></v-progress-circular> -->
  103. <v-btn :loading="codeIsLoading" text small>
  104. <template v-if="codeIsLoading">加载中</template>
  105. <template v-else-if="codeHasMore">加载更多</template>
  106. <template v-else>没有更多</template>
  107. </v-btn>
  108. </div>
  109. </div>
  110. </div>
  111. <!-- <div class="code-list">
  112. <div
  113. v-for="(item, index) in 10"
  114. :key="index"
  115. class="code-item"
  116. ></div>
  117. </div> -->
  118. </activity-invite-user-box>
  119. <activity-invite-user-box class="box4">
  120. <template #title>活动规则</template>
  121. <!-- eslint-disable-next-line vue/no-v-html -->
  122. <div class="text-sm" v-html="activityRules"></div>
  123. </activity-invite-user-box>
  124. <!-- <div class="">invite-user</div> -->
  125. <!-- <button>刷新数据</button> -->
  126. <!-- <div class="">{{ data }}</div> -->
  127. <!-- <div class="text-center">
  128. <span>分享好友购买云机套餐<br />返星币换现金</span>
  129. </div>
  130. <div class="text-center mt-4">
  131. <van-button type="primary" @click="share()">邀请好友</van-button>
  132. </div>
  133. <van-icon name="chat-o" />
  134. <van-icon name="shape-plus" class-prefix="mdi" />
  135. <van-button @click="$fetch()">刷新</van-button>
  136. <div class="ccc">{{ 36666666.123456 | formatNumber }}</div>
  137. <div class="ccc">{{ '2020-01-01' | formatDate }}</div> -->
  138. </v-container>
  139. </template>
  140. <script>
  141. // import qs from 'qs';
  142. // import clipboard from 'clipboardy/browser';
  143. // import * as clipboard from 'clipboard-polyfill/text';
  144. // console.log("🚀 ~ file: index.vue ~ line 176 ~ clipboard", clipboard)
  145. // import { getStarCoinOverview } from '~/api/activity/invite-user.js';
  146. // import { getContentByType } from '~/api/public/agreement.js';
  147. export default {
  148. // auth: false,
  149. name: 'InviteUser',
  150. filters: {
  151. activationCodeMask(value) {
  152. // 微信环境不支持零宽断言
  153. // return value.replace(/(?<=^.{4})(.*)(?=.{4}$)/, '***');
  154. return value.replace(/(.{4})(.*)(.{4}$)/, '$1***$3');
  155. },
  156. },
  157. // async asyncData({ $axios }) {
  158. // // 页面初始化前触发
  159. // const res = await $axios.$get(
  160. // '/activity/v1/inviteUser/orderRelation/starCoinOverview',
  161. // );
  162. // res.data.type = 2;
  163. // return {
  164. // data: res.data,
  165. // };
  166. // },
  167. data() {
  168. return {
  169. data: {
  170. todayIncomeStarCoin: 0,
  171. totalIncomeStarCoin: 0,
  172. todayBuyOrderCount: 0,
  173. totalBuyOrderCount: 0,
  174. todayBuyOrderSuccessCount: 0,
  175. totalBuyOrderSuccessCount: 0,
  176. withdrawStarCoinNum: 0,
  177. inviteUserName: null,
  178. activityId: null,
  179. status: 0,
  180. type: 0,
  181. },
  182. activityRules: '',
  183. myActivationCode: [],
  184. myCodeFrom: {
  185. activityId: null,
  186. pageNum: 1,
  187. pageSize: 8,
  188. },
  189. codeTotal: -1,
  190. codeIsLoading: false,
  191. };
  192. },
  193. async fetch() {
  194. // 页面初始化后触发
  195. try {
  196. await this.getActiveInfo();
  197. this.$native.setShareInfo(this.shareInfo);
  198. await Promise.all([
  199. this.getActivityRules(),
  200. this.type === 2 && this.getMyActivationCode(this.myCodeFrom),
  201. ]);
  202. } catch (error) {
  203. this.$toast.error(error.message);
  204. }
  205. },
  206. head: {
  207. title: '邀请好友',
  208. // share: {
  209. // title: '标题',
  210. // content: '内容',
  211. // gotoUrl: 'http://localhost',
  212. // shareImg: 'http://localhost',
  213. // },
  214. },
  215. computed: {
  216. returnContent() {
  217. return {
  218. 1: {
  219. img: require('@/assets/image/activity/invite-user/cybz-content@2x.png'),
  220. content: '返星币换现金',
  221. },
  222. 2: {
  223. img: require('@/assets/image/activity/invite-user/cybz-content-2@2x.png'),
  224. content: '返云机时长',
  225. },
  226. 3: {
  227. img: require('@/assets/image/activity/invite-user/cybz-content-3@2x.png'),
  228. content: '返积分',
  229. },
  230. }[this.type];
  231. },
  232. // contentImg() {
  233. // return {
  234. // 1: require('@/assets/image/activity/invite-user/cybz-content@2x.png'),
  235. // 2: require('@/assets/image/activity/invite-user/cybz-content-2@2x.png'),
  236. // 3: require('@/assets/image/activity/invite-user/cybz-content-3@2x.png'),
  237. // }[this.type];
  238. // },
  239. // returnContent() {
  240. // return { 1: '返星币换现金', 2: '返云机时长', 3: '返积分' }[this.type];
  241. // },
  242. codeHasMore() {
  243. return (
  244. this.codeTotal < 0 ||
  245. this.myCodeFrom.pageNum * this.myCodeFrom.pageSize < this.codeTotal
  246. );
  247. },
  248. dataList() {
  249. switch (this.type) {
  250. case 1: {
  251. return [
  252. { label: '今日收益(星币)', value: this.data.todayIncomeStarCoin },
  253. { label: '总收益(星币)', value: this.data.totalIncomeStarCoin },
  254. {
  255. label: '今日购买订单数',
  256. value: this.data.todayBuyOrderSuccessCount,
  257. },
  258. { label: '累计推广订单', value: this.data.totalBuyOrderCount },
  259. {
  260. label: '今日购买成功客户',
  261. value: this.data.todayBuyOrderSuccessCount,
  262. },
  263. {
  264. label: '累计购买成功客户',
  265. value: this.data.totalBuyOrderSuccessCount,
  266. },
  267. // { label: '可提现星币数量', value: this.data.withdrawStarCoinNum },
  268. ];
  269. }
  270. case 2: {
  271. return [
  272. {
  273. label: '今日获取的激活码',
  274. value: this.data.todayIncomeActivationCode,
  275. },
  276. { label: '总激活码', value: this.data.totalIncomeActivationCode },
  277. {
  278. label: '今日购买订单数',
  279. value: this.data.todayBuyOrderSuccessCount,
  280. },
  281. { label: '累计推广订单', value: this.data.totalBuyOrderCount },
  282. {
  283. label: '今日购买成功客户',
  284. value: this.data.todayBuyOrderSuccessCount,
  285. },
  286. {
  287. label: '累计购买成功客户',
  288. value: this.data.totalBuyOrderSuccessCount,
  289. },
  290. // { label: '可提现星币数量', value: this.data.withdrawStarCoinNum },
  291. ];
  292. }
  293. case 3: {
  294. return [
  295. {
  296. label: '今日获取的积分',
  297. value: this.data.todayIncomeIntegral,
  298. },
  299. { label: '总积分', value: this.data.totalIncomeIntegral },
  300. {
  301. label: '今日购买订单数',
  302. value: this.data.todayBuyOrderSuccessCount,
  303. },
  304. { label: '累计推广订单', value: this.data.totalBuyOrderCount },
  305. {
  306. label: '今日购买成功客户',
  307. value: this.data.todayBuyOrderSuccessCount,
  308. },
  309. {
  310. label: '累计购买成功客户',
  311. value: this.data.totalBuyOrderSuccessCount,
  312. },
  313. // { label: '可提现星币数量', value: this.data.withdrawStarCoinNum },
  314. ];
  315. }
  316. default: {
  317. return [];
  318. }
  319. }
  320. },
  321. type() {
  322. return this.data.type;
  323. },
  324. shareUrl() {
  325. return (
  326. location.origin +
  327. this.$router.resolve({
  328. path: '/activity/invite-user/register',
  329. query: {
  330. invitationUserName: this.data.inviteUserName,
  331. activityId: this.data.activityId,
  332. type: this.type,
  333. },
  334. }).href
  335. );
  336. },
  337. shareInfo() {
  338. if (this.$userAgent.isMiniProgram) {
  339. return {
  340. title: '双子星APP',
  341. path: '/pages/home/home',
  342. imgUrl: location.origin + require('~/assets/image/logo.png'),
  343. };
  344. }
  345. return {
  346. title: '双子星APP',
  347. desc: `分享好友购买云机套餐,${this.returnContent?.content}`,
  348. link: this.shareUrl,
  349. imgUrl: location.origin + require('~/assets/image/logo.png'),
  350. };
  351. },
  352. },
  353. mounted() {
  354. // this.$userAgent.isMiniProgram &&
  355. // this.$wx.miniProgram.postMessage({
  356. // data: {
  357. // action: 'updateAppMessageShareData',
  358. // params: {
  359. // title: '双子星云手机',
  360. // path: '/pages/home/home',
  361. // imageUrl:
  362. // location.origin +
  363. // require('~/assets/image/activity/invite-user/bg@2x.png'),
  364. // // promise: null,
  365. // },
  366. // },
  367. // });
  368. },
  369. methods: {
  370. async getActiveInfo() {
  371. const res = await this.$axios.$get(
  372. '/activity/v1/inviteUser/orderRelation/starCoinOverview',
  373. );
  374. // res.data.type = 2;
  375. this.data = res.data;
  376. this.myCodeFrom.activityId = res.data.activityId;
  377. },
  378. async getMyActivationCode(params) {
  379. try {
  380. this.codeIsLoading = true;
  381. const res = await this.$axios.$get(
  382. '/activity/v1/inviteUser/orderRelation/myActivationCode',
  383. {
  384. params,
  385. },
  386. );
  387. this.codeTotal = res.data.total;
  388. this.myActivationCode.push(
  389. ...(res.data.list ?? []),
  390. // ...Array.from({ length: 8 }).fill({
  391. // createTime: '2022-08-01 14:33:11',
  392. // activationCode: 'XXXXXXXXXXXXXXXXXXX',
  393. // activationUse: 1,
  394. // }),
  395. );
  396. this.myCodeFrom = params;
  397. } finally {
  398. this.codeIsLoading = false;
  399. }
  400. },
  401. async share() {
  402. // console.log(this);
  403. if (this.data.status !== 1) {
  404. if (this.data.status === 0) {
  405. throw new Error('当前活动已过期');
  406. }
  407. if (this.data.status === 2) {
  408. throw new Error('当前活动未开启');
  409. }
  410. if (this.data.status === 3) {
  411. throw new Error('当前活动已结束');
  412. }
  413. throw new Error('未知活动状态');
  414. }
  415. this.$tongji.trackEvent('活动', '分享', '', 0);
  416. // if (this.$userAgent.isMiniProgram) {
  417. // // 小程序环境
  418. // await clipboard.writeText(`${this.shareInfo.gotoUrl} 唔即云手机`);
  419. // this.$toast.success('链接复制成功');
  420. // } else
  421. if (this.$userAgent.isSzx || this.$userAgent.isSzxBrowser) {
  422. // app环境
  423. this.$native.share(this.shareInfo);
  424. } else {
  425. // 浏览器环境
  426. await this.$native.clipboard.writeText(`${this.shareUrl} 双子星云手机`);
  427. // throw new Error('1231');
  428. this.$toast.success('链接复制成功');
  429. }
  430. },
  431. async getActivityRules() {
  432. const agreementCoding = {
  433. 1: 'iuserrules01',
  434. 2: 'iuserrules02',
  435. 3: 'iuserrules03',
  436. }[this.type];
  437. if (agreementCoding) {
  438. const res = await this.$axios.$get(
  439. '/public/v5/agreementApi/content/getContentByType',
  440. {
  441. params: {
  442. agreementCoding,
  443. type: 1,
  444. },
  445. },
  446. );
  447. this.activityRules = res.data.content
  448. .replace(/[\d\D]*<body>([\d\D]+)<\/body>[\d\D]*/i, '$1')
  449. .replace(/<div class="phone-container">([\d\D]+)<\/div>/g, '$1');
  450. }
  451. },
  452. async copyCode(item) {
  453. await this.$native.clipboard.writeText(item.activationCode);
  454. this.$toast.success('复制成功');
  455. },
  456. codeLoadMoreIntersect(event) {
  457. if (event[0].isIntersecting && this.codeHasMore && !this.codeIsLoading) {
  458. this.getMyActivationCode({
  459. ...this.myCodeFrom,
  460. pageNum: this.myCodeFrom.pageNum + 1,
  461. });
  462. }
  463. },
  464. },
  465. };
  466. </script>
  467. <style lang="scss" scoped>
  468. .invite-user {
  469. color: #333;
  470. // background-image: url('~/assets/image/activity/invite-user/bg@2x.png');
  471. background-size: 100% auto;
  472. // background-position-y: -44px;
  473. overflow: hidden;
  474. padding: 0;
  475. // padding-bottom: 30px;
  476. padding-bottom: env(safe-area-inset-bottom, 30px);
  477. background-color: #9525e3;
  478. &.bg-1 {
  479. background-image: url('~/assets/image/activity/invite-user/bg@2x.png');
  480. }
  481. &.bg-2 {
  482. background-image: url('~/assets/image/activity/invite-user/bg-2@2x.png');
  483. }
  484. &.bg-3 {
  485. background-image: url('~/assets/image/activity/invite-user/bg-3@2x.png');
  486. }
  487. }
  488. // .box {
  489. // width: 373px;
  490. // box-sizing: border-box;
  491. // margin: auto;
  492. // // border-image-width: 200px;
  493. // // border-image-slice: 200%;
  494. // // border-width: 1px;
  495. // position: relative;
  496. // z-index: 0;
  497. // + .box {
  498. // margin-top: 30px;
  499. // }
  500. // .box-header {
  501. // // position: absolute;
  502. // position: relative;
  503. // // top: -30px;
  504. // z-index: 1;
  505. // // left: 141px;
  506. // // left: 0;
  507. // // right: 0;
  508. // margin-bottom: -34px;
  509. // // text-align: center;
  510. // // padding: 0 130px;
  511. // display: flex;
  512. // align-items: center;
  513. // justify-content: center;
  514. // flex-direction: column;
  515. // .box-header-content {
  516. // color: #fff;
  517. // border-image-source: url('~/assets/image/activity/invite-user/box-title@2x.png');
  518. // border-image-slice: 0 140 fill;
  519. // border-width: 0 70px 0;
  520. // border-style: solid;
  521. // height: 38px;
  522. // display: flex;
  523. // align-items: center;
  524. // justify-content: center;
  525. // flex-direction: column;
  526. // // width: auto;
  527. // }
  528. // }
  529. // .box-main {
  530. // z-index: 0;
  531. // // padding: 30px 15px 20px;
  532. // border-image-source: url('~/assets/image/activity/invite-user/box-bg@2x.png');
  533. // border-image-slice: 50 60 80 fill;
  534. // border-image-width: 30px 30px 40px;
  535. // border-width: 50px 20px 40px;
  536. // border-style: solid;
  537. // // padding-top: 30px;
  538. // }
  539. // }
  540. .box1 {
  541. margin-top: 275px;
  542. // ::v-deep .box-main {
  543. // // padding: 30px 15px 20px;
  544. // padding-left: 0;
  545. // padding-right: 0;
  546. // }
  547. .cybz-content {
  548. width: 305px;
  549. height: 75px;
  550. margin: auto;
  551. display: block;
  552. // margin-top: 30px;
  553. }
  554. .cybz-content-text {
  555. // display: flex;
  556. display: grid;
  557. // width: 305px;
  558. // padding: 0 28px;
  559. // align-items: center;
  560. // margin: auto;
  561. // justify-content: space-between;
  562. grid-template-columns: 1fr 1fr 1fr;
  563. font-size: 12px;
  564. color: #333;
  565. .cybz-content-text-item {
  566. // width: 0;
  567. // flex: auto;
  568. text-align: center;
  569. }
  570. }
  571. .share-button {
  572. display: block;
  573. margin: auto;
  574. width: 302px !important;
  575. height: 62px !important;
  576. background-image: url('~/assets/image/activity/invite-user/share-button@2x.png');
  577. background-size: 100% 100%;
  578. margin-top: 24px;
  579. // margin-bottom: 24px;
  580. color: #dd1b0d;
  581. font-size: 22px;
  582. font-weight: bold;
  583. }
  584. }
  585. .box2 {
  586. .label {
  587. // font-size: 14px;
  588. }
  589. .value {
  590. color: #ff6600;
  591. // font-size: 24px;
  592. }
  593. ::v-deep .box-main {
  594. padding-left: 20px;
  595. padding-right: 20px;
  596. }
  597. }
  598. .box3 {
  599. ::v-deep .box-main {
  600. // padding-left: 20px;
  601. // padding-top: 0;
  602. padding-left: 10px;
  603. padding-right: 10px;
  604. }
  605. }
  606. .code-table {
  607. .table-body {
  608. max-height: 30px * 8;
  609. overflow-y: auto;
  610. }
  611. .time-col {
  612. width: 120px;
  613. }
  614. .status-col {
  615. width: 60px;
  616. }
  617. // width: 100%;
  618. tr {
  619. height: 30px;
  620. color: #666;
  621. }
  622. td {
  623. height: 30px;
  624. color: #333;
  625. }
  626. // tbody {
  627. // // max-height: 200px;
  628. // // overflow-y: auto;
  629. // // display: block;
  630. // }
  631. .copy-btn {
  632. min-width: 0 !important;
  633. height: auto !important;
  634. padding: 0 !important;
  635. }
  636. }
  637. .box4::v-deep .box-main {
  638. padding-left: 10px;
  639. padding-right: 10px;
  640. }
  641. </style>