Authored by 毕凯

Merge remote-tracking branch 'origin/feature/newQrcode' into release/6.1

  1 +'use script';
  2 +
  3 +const headerModel = require('../../../doraemon/models/header'); // 头部model
  4 +const newQrcodeModel = require('../models/newQrcode');
  5 +
  6 +exports.index = (req, res, next) => {
  7 + let responseData = {
  8 + module: 'home',
  9 + page: 'new-qrcode',
  10 + pageHeader: headerModel.setNav({
  11 + navTitle: '我的二维码'
  12 + }),
  13 + title: '我的二维码',
  14 + width750: true,
  15 + localCss: true
  16 + };
  17 +
  18 + let params = {
  19 + uid: req.user.uid
  20 + };
  21 +
  22 + req.ctx(newQrcodeModel).index(params).then(result => {
  23 + res.render('new-qrcode', Object.assign(responseData, result));
  24 + }).catch(next);
  25 +};
  26 +
  27 +exports.reload = (req, res, next) => {
  28 + let params = {
  29 + uid: req.user.uid
  30 + };
  31 +
  32 + req.ctx(newQrcodeModel).getToken(params).then(result => {
  33 + res.json(result);
  34 + }).catch(next);
  35 +};
  1 +'use strict';
  2 +
  3 +const _ = require('lodash');
  4 +const camelCase = global.yoho.camelCase;
  5 +const api = global.yoho.API;
  6 +const crypto = global.yoho.crypto;
  7 +const PASSWORD = 'yoho9646yoho9646';
  8 +
  9 +class newQrcode extends global.yoho.BaseModel {
  10 + constructor(ctx) {
  11 + super(ctx);
  12 + }
  13 +
  14 + userInfo(params) {
  15 + if (params.uid) {
  16 + return api.get('', {
  17 + method: 'app.passport.profile',
  18 + uid: params.uid
  19 + }, {
  20 + code: 200
  21 + });
  22 + } else {
  23 + return Promise.resolve({});
  24 + }
  25 + }
  26 +
  27 + getCode(params) {
  28 + if (params.uid) {
  29 + return api.get('', {
  30 + method: 'app.invitecode.my',
  31 + uid: params.uid
  32 + }, {
  33 + code: 200
  34 + });
  35 + } else {
  36 + return Promise.resolve({});
  37 + }
  38 + }
  39 +
  40 + getToken(params) {
  41 + let uidNum = parseInt(params.uid, 10);
  42 + let token = uidNum ? crypto.encryption(PASSWORD, uidNum + '') : '';
  43 + let uid = '';
  44 +
  45 + try {
  46 + uid = crypto.decrypt(PASSWORD, decodeURIComponent(token));
  47 + uid = parseInt(uid, 10);
  48 + } catch (e) {
  49 + uid = token;
  50 + }
  51 +
  52 + return api.get('', {
  53 + method: 'app.twoDimen.getCode',
  54 + uid: uid,
  55 + }).then(result => {
  56 + return (result && result.data && result.data.code) || '';
  57 + });
  58 + }
  59 +
  60 + index(params) {
  61 + return api.all([
  62 + this.userInfo(params),
  63 + this.getCode(params),
  64 + this.getToken(params)
  65 + ]).then(result => {
  66 + let resu = {};
  67 +
  68 + if (_.get(result, '[0]data')) {
  69 + resu = camelCase(result[0].data);
  70 + }
  71 + if (_.get(result, '[1]data')) {
  72 + resu.trendWord = result[1].data.trendWord;
  73 + }
  74 + if (_.get(result, '[2]')) {
  75 + resu.token = result[2];
  76 + }
  77 + return resu;
  78 + });
  79 + }
  80 +}
  81 +
  82 +module.exports = newQrcode;
@@ -31,8 +31,8 @@ const gradeNew = require(`${cRoot}/grade-new`); @@ -31,8 +31,8 @@ const gradeNew = require(`${cRoot}/grade-new`);
31 const refund = require(`${cRoot}/refund`); 31 const refund = require(`${cRoot}/refund`);
32 const exchange = require(`${cRoot}/exchange`); 32 const exchange = require(`${cRoot}/exchange`);
33 const tideCommand = require(`${cRoot}/tide-command`); 33 const tideCommand = require(`${cRoot}/tide-command`);
34 -  
35 const newHome = require(`${cRoot}/new-home`); 34 const newHome = require(`${cRoot}/new-home`);
  35 +const newQrcode = require(`${cRoot}/newQrcode`);
36 36
37 // const myDetail = require(`${cRoot}/myDetail); 37 // const myDetail = require(`${cRoot}/myDetail);
38 38
@@ -179,5 +179,8 @@ router.get('/return/exchange/refreshDelivery', auth, exchange.refreshDelivery); @@ -179,5 +179,8 @@ router.get('/return/exchange/refreshDelivery', auth, exchange.refreshDelivery);
179 179
180 router.get('/tide-command', auth, tideCommand.tideCommand); // 设置潮流口令 180 router.get('/tide-command', auth, tideCommand.tideCommand); // 设置潮流口令
181 181
182 -router.get('/', newHome.index); // 设置潮流口令 182 +router.get('/', newHome.index);
  183 +router.get('/newQrcode', auth, newQrcode.index); // 新二维码页面
  184 +router.get('/newQrcode/reload', auth, newQrcode.reload); // 刷新二维码页面
  185 +
183 module.exports = router; 186 module.exports = router;
  1 +<div class="new-qrcode-c">
  2 + <div class="qrcode-body">
  3 + <div class="toper">
  4 + <div class="user-pic">
  5 + <div class="avatar user-avatar"{{#if headIco}} style="background-image:url({{image2 headIco mode=2 h=100 w=100 q=90}})"{{/if}}></div>
  6 + <div class="level level-{{vipInfo/curLevel}}"></div>
  7 + </div>
  8 + <div class="user-info">
  9 + <div class="name eps">{{nickname}}</div>
  10 + <div class="passcode">
  11 + <div class="dot">#&nbsp;</div>
  12 + <div class="auto-scroll">
  13 + <div class="scroll-words go-scroll">{{trendWord}}</div>
  14 + </div>
  15 + <div class="dot">&nbsp;#</div>
  16 + </div>
  17 + </div>
  18 + </div>
  19 + <div class="qrcode-pic" data-qr="{{token}}">
  20 + <div class="qrcode-avatar user-avatar"{{#if headIco}} style="background-image:url({{image2 headIco mode=2 h=100 w=100 q=90}})"{{/if}}></div>
  21 + </div>
  22 + <div class="invite hide">
  23 + <span>邀请好友扫一扫完成注册,现金券赚不停</span>
  24 + <span class="iconfont">&#xe639;</span>
  25 + </div>
  26 + </div>
  27 + <div class="reload"><span class="iconfont">&#xe733;</span>点击刷新二维码</div>
  28 +</div>
No preview for this file type
@@ -351,6 +351,9 @@ t9.5 -10.5t21.5 -4h37h67h81h80h64h36q23 0 34 12t2 38q-5 13 -9.5 30.5t-9.5 34.5q- @@ -351,6 +351,9 @@ t9.5 -10.5t21.5 -4h37h67h81h80h64h36q23 0 34 12t2 38q-5 13 -9.5 30.5t-9.5 34.5q-
351 <glyph glyph-name="yoho-coin" unicode="&#59186;" d="M512 153.6h-40.96a195.87072 195.87072 0 0 0-45.4656 5.34528l14.29504 59.76064a134.5536 134.5536 0 0 1 31.15008-3.66592h40.96c73.40032 0 133.12 59.71968 133.12 133.12V592.40448h61.44V348.16c0.02048-107.27424-87.26528-194.56-194.53952-194.56zM512 296.96c-107.27424 0-194.56 87.28576-194.56 194.56v101.56032h61.44v-101.56032c0-73.40032 59.71968-133.12 133.12-133.12s133.12 59.71968 133.12 133.12v103.1168h61.44v-103.1168c0-107.27424-87.28576-194.56-194.56-194.56zM512-51.2c-242.7904 0-440.32 197.5296-440.32 440.32S269.2096 829.44 512 829.44s440.32-197.5296 440.32-440.32-197.5296-440.32-440.32-440.32z m0 819.2c-208.91648 0-378.88-169.96352-378.88-378.88s169.96352-378.88 378.88-378.88 378.88 169.96352 378.88 378.88S720.91648 768 512 768z" horiz-adv-x="1024" /> 351 <glyph glyph-name="yoho-coin" unicode="&#59186;" d="M512 153.6h-40.96a195.87072 195.87072 0 0 0-45.4656 5.34528l14.29504 59.76064a134.5536 134.5536 0 0 1 31.15008-3.66592h40.96c73.40032 0 133.12 59.71968 133.12 133.12V592.40448h61.44V348.16c0.02048-107.27424-87.26528-194.56-194.53952-194.56zM512 296.96c-107.27424 0-194.56 87.28576-194.56 194.56v101.56032h61.44v-101.56032c0-73.40032 59.71968-133.12 133.12-133.12s133.12 59.71968 133.12 133.12v103.1168h61.44v-103.1168c0-107.27424-87.28576-194.56-194.56-194.56zM512-51.2c-242.7904 0-440.32 197.5296-440.32 440.32S269.2096 829.44 512 829.44s440.32-197.5296 440.32-440.32-197.5296-440.32-440.32-440.32z m0 819.2c-208.91648 0-378.88-169.96352-378.88-378.88s169.96352-378.88 378.88-378.88 378.88 169.96352 378.88 378.88S720.91648 768 512 768z" horiz-adv-x="1024" />
352 352
353 353
  354 + <glyph glyph-name="sx" unicode="&#59187;" d="M810.72128 293.49888a40.89856 40.89856 0 0 1-55.27552-17.28512 237.42464 237.42464 0 0 0-81.08032-89.04704 237.6704 237.6704 0 0 0-239.06304-11.07968 235.7248 235.7248 0 0 0-116.36736 139.34592 235.58144 235.58144 0 0 0 16.24064 180.81792 235.6224 235.6224 0 0 0 139.34592 116.34688 235.4176 235.4176 0 0 0 180.81792-16.26112l1.04448-0.59392-0.94208-0.16384a40.98048 40.98048 0 0 1 13.47584-80.81408l99.75808 16.65024a40.96 40.96 0 0 1 33.66912 47.14496l-16.62976 99.75808a40.96 40.96 0 0 1-80.81408-13.47584l0.49152-2.90816c-4.01408 2.33472-7.92576 4.8128-12.06272 6.98368a316.94848 316.94848 0 0 1-243.24096 21.87264 316.86656 316.86656 0 0 1-187.45344-156.54912C181.02272 378.368 241.43872 185.1392 397.312 103.5264a318.42304 318.42304 0 0 1 147.92704-36.31104c60.60032 0 121.05728 17.16224 173.62944 51.15904a319.13984 319.13984 0 0 1 109.1584 119.84896 40.96 40.96 0 0 1-17.3056 55.27552z" horiz-adv-x="1024" />
  355 +
  356 +
354 357
355 358
356 </font> 359 </font>
No preview for this file type
No preview for this file type
  1 +import 'home/new-qrcode.page.css';
  2 +import $ from 'yoho-jquery';
  3 +import Page from 'yoho-page';
  4 +import 'yoho-jquery-qrcode';
  5 +
  6 +class NewQrcode extends Page {
  7 + constructor() {
  8 + super();
  9 +
  10 + this.selector = {
  11 + $qrcodePic: $('.qrcode-pic'),
  12 + $autoScroll: $('.auto-scroll'),
  13 + $scrollWords: $('.scroll-words'),
  14 + $reload: $('.reload')
  15 + };
  16 +
  17 + this.qrText = '';
  18 + this.auto = '';
  19 + this.init();
  20 + }
  21 +
  22 + init() {
  23 + this.drawQrcode();
  24 + this.autoScroll();
  25 + this.bindEvents();
  26 + this.autoReload();
  27 + }
  28 +
  29 + bindEvents() {
  30 + this.selector.$reload.on('click', this.reload.bind(this));
  31 + }
  32 +
  33 + autoReload() {
  34 + this.auto = setInterval(() => {
  35 + this.reload();
  36 + }, 110 * 1000); // 110秒自动刷新一次
  37 + }
  38 +
  39 + reload() {
  40 + this.ajax({
  41 + url: '/home/newQrcode/reload',
  42 + }).then(result => {
  43 + if (result) {
  44 + this.qrText = result;
  45 + this.selector.$qrcodePic.find('canvas').remove();
  46 + this.drawQrcode();
  47 + clearInterval(this.auto);
  48 + this.autoReload();
  49 + }
  50 + }).catch(error => {
  51 + console.error(error);
  52 + });
  53 + }
  54 +
  55 + drawQrcode() {
  56 + this.selector.$qrcodePic.qrcode({
  57 + render: 'canvas', // 显示方式,canvas,image和div
  58 + text: this.qrText || this.selector.$qrcodePic.data('qr'), // 二维码的内容
  59 + size: parseInt(420, 10), // 大小
  60 + ecLevel: 'H', // 纠错级别
  61 + });
  62 + }
  63 +
  64 + autoScroll() {
  65 + let containerWidth = this.selector.$autoScroll.width();
  66 + let innerWidth = this.selector.$scrollWords.width();
  67 +
  68 + if (innerWidth <= containerWidth) {
  69 + this.selector.$scrollWords.removeClass('go-scroll');
  70 + }
  71 + }
  72 +}
  73 +
  74 +$(() => {
  75 + new NewQrcode();
  76 +});
  1 +body,
  2 +html {
  3 + background-image: linear-gradient(#131313, #3e3e3e);
  4 + background-repeat: no-repeat;
  5 + min-height: 100%;
  6 + background-color: #3e3e3e;
  7 +}
  8 +
  9 +.new-qrcode-c {
  10 + width: 750px;
  11 + overflow: hidden;
  12 + position: relative;
  13 +
  14 + .eps {
  15 + white-space: nowrap;
  16 + overflow: hidden;
  17 + text-overflow: ellipsis;
  18 + }
  19 +
  20 + .user-avatar {
  21 + background-image: resolve("home/index/user-avatar.png");
  22 + }
  23 +
  24 + .qrcode-body {
  25 + width: 560px;
  26 + height: 784px;
  27 + border-radius: 6px;
  28 + background-color: #fff;
  29 + margin: 100px auto 213px;
  30 + padding: 50px;
  31 +
  32 + .toper {
  33 + height: 100px;
  34 +
  35 + .user-pic {
  36 + width: 100px;
  37 + height: 100px;
  38 + float: left;
  39 + position: relative;
  40 +
  41 + .level {
  42 + width: 60px;
  43 + height: 25px;
  44 + position: absolute;
  45 + bottom: -12px;
  46 + left: 20px;
  47 + }
  48 +
  49 + .level-1 {
  50 + background-image: url("/home/new-qrcode/vip-1.png");
  51 + }
  52 +
  53 + .level-2 {
  54 + background-image: url("/home/new-qrcode/vip-2.png");
  55 + }
  56 +
  57 + .level-3 {
  58 + background-image: url("/home/new-qrcode/vip-3.png");
  59 + }
  60 + }
  61 +
  62 + .avatar {
  63 + width: 100%;
  64 + height: 100%;
  65 + background-position: center center;
  66 + background-size: contain;
  67 + border-radius: 50%;
  68 + overflow: hidden;
  69 + }
  70 +
  71 + .user-info {
  72 + width: 360px;
  73 + height: 100px;
  74 + float: left;
  75 + padding-left: 20px;
  76 + color: #444;
  77 + }
  78 +
  79 + .name {
  80 + line-height: 50px;
  81 + font-size: 34px;
  82 + }
  83 +
  84 + .passcode {
  85 + line-height: 50px;
  86 + font-size: 28px;
  87 +
  88 + div {
  89 + float: left;
  90 + }
  91 +
  92 + .tip {
  93 + width: 20px;
  94 + }
  95 +
  96 + .dot {
  97 + width: 30px;
  98 + }
  99 +
  100 + .auto-scroll {
  101 + max-width: 280px;
  102 + height: 50px;
  103 + overflow: hidden;
  104 + position: relative;
  105 + }
  106 +
  107 + .scroll-words {
  108 + position: relative;
  109 + top: 0;
  110 + left: 0;
  111 + white-space: nowrap;
  112 + }
  113 +
  114 + .go-scroll {
  115 + animation-name: autoScroll;
  116 + animation-duration: 5s;
  117 + animation-timing-function: linear;
  118 + animation-iteration-count: infinite;
  119 + animation-direction: alternate;
  120 + animation-delay: 2s;
  121 + }
  122 + }
  123 + }
  124 +
  125 + .qrcode-pic {
  126 + width: 460px;
  127 + height: 460px;
  128 + margin: 47px auto 0;
  129 + position: relative;
  130 +
  131 + canvas {
  132 + width: 460px;
  133 + height: 460px;
  134 + }
  135 +
  136 + .qrcode-avatar {
  137 + width: 110px;
  138 + height: 110px;
  139 + position: absolute;
  140 + top: 50%;
  141 + left: 50%;
  142 + margin-top: -55px;
  143 + margin-left: -55px;
  144 + background-position: center center;
  145 + background-size: contain;
  146 + border-radius: 50%;
  147 + overflow: hidden;
  148 + border: solid 5px #fff;
  149 + }
  150 + }
  151 +
  152 + .invite {
  153 + margin-top: 30px;
  154 +
  155 + span {
  156 + font-size: 24px;
  157 + color: #444;
  158 + }
  159 + }
  160 + }
  161 +
  162 + .reload {
  163 + position: fixed;
  164 + bottom: 54px;
  165 + left: 50%;
  166 + font-size: 24px;
  167 + color: #b0b0b0;
  168 + width: 200px;
  169 + line-height: 30px;
  170 + margin-left: -100px;
  171 + text-align: center;
  172 +
  173 + span {
  174 + font-size: 40px;
  175 + color: #eee;
  176 + position: absolute;
  177 + top: 0;
  178 + left: -30px;
  179 + }
  180 + }
  181 +}
  182 +
  183 +@keyframes autoScroll {
  184 + from {
  185 + left: 0;
  186 + }
  187 +
  188 + to {
  189 + left: -180px;
  190 + }
  191 +}