index.vue 19 KB

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