index.vue 17 KB

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