app-share-page.vue 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
<template>
    <div class="app-share-page">
        <div class="content-container">
            <img src="@/assets/img/logo.png"/>
            <span class="apply">{{ userName }} {{$t('components.appsharepage.invite')}}</span>
            <button class="apply-button" @click='applyShareOptions'>{{ $t('components.appsharepage.apply') }}</button>
            <button class="cancel-button" @click='cancel'>{{ $t('components.appsharepage.cancel') }}</button>
        </div>
    </div>
</template>

<script lang="ts">
import qs from 'qs';
import { Vue, Component } from 'vue-property-decorator';

@Component({})
export default class AppSharePage extends Vue{
    
    /**
     * 链接参数
     *
     * @type {*}
     * @memberof AppShareTheme
     */
    public urlParams: any = {};

    /**
     * 分享用户
     *
     * @type {*}
     * @memberof AppShareTheme
     */
    public userName: any;

    /**
     * vue生命周期 -- created
     *
     * @memberof AppShareTheme
     */
    public created() {
        this.urlParams = this.parseViewParam(window.location.href);
        this.userName = decodeURIComponent(this.urlParams['shareUserName']);
    }

    /**
     * vue生命周期 -- mounted
     *
     * @memberof AppShareTheme
     */
    public mounted() {
        setTimeout(() => {
            const el = document.getElementById('app-loading-x');
            if (el) {
                el.style.display = 'none';
            }
        }, 300);
    }

    /**
     * 处理路径数据
     *
     * @param {*} [urlStr] 路径
     * @memberof AppShareTheme
     */
    public parseViewParam(urlStr: string): any {
        let tempViewParam: any = {};
        const tempViewparam: any = urlStr.slice(urlStr.lastIndexOf('?') + 1);
        const viewparamArray: Array<string> = decodeURIComponent(tempViewparam).split(';');
        if (viewparamArray.length > 0) {
            viewparamArray.forEach((item: any) => {
                Object.assign(tempViewParam, qs.parse(item));
            });
        }
        return tempViewParam;
    }

    /**
     * 应用分享配置
     *
     * @memberof AppShareTheme
     */
    public applyShareOptions() {
        let url: string = '/share?';
        Object.keys(this.urlParams).forEach((param: any, index: number) => {
            url += `${param}=${this.urlParams[param]}${index == Object.keys(this.urlParams).length - 1 ? '' : '&'}`;
        })
        this.$router.push(url);
    }

    /**
     * 取消应用
     *
     * @memberof AppShareTheme
     */
    public cancel() {
        this.$router.push('/appindexview');
    }
}
</script>

<style lang="less">
@import './app-share-page.less';
</style>