anchor.js 2.02 KB
import { parse } from '../../../vendors/query-stringify';
import { tapGoBind } from '../../../common/login';
import event from '../../../common/event';
import tool from '../../../common/tool';

Component({
    properties: {
        url: {
            type: String,
            value: ''
        },
        tid: {
            type: String,
            value: ''
        },
        tName: {
            type: String,
            value: ''
        },
        tIndex: {
            type: Number,
            value: 1
        },
        tFindex: {
            type: Number,
            value: 1
        },
        isFloor: {
            type: Number,
            value: 0
        }
    },
    data: {
      needLogin: false
    },
    ready: function () {
      if (!this.data.url) {
        return false;
      }

      const url = this.data.url;
      const search = url.split('?')[1] || '';
      const qs = parse(search);

      if (qs.needLogin && Number(qs.needLogin) === 1) {
        const app = getApp() || {};
        if (!app.getUid || !app.getUid()) {
          this.setData({ needLogin: true })
        } else {
          this.setData({ needLogin: false })
        }
      }
    },
    methods: {
        jumpTo: function() {
            if (!this.data.url) {
                return false;
            }

            const url = this.data.url;
            const search = url.split('?')[1] || '';
            const qs = parse(search);

            if (qs.toolName && tool[qs.toolName]) {
                return tool[qs.toolName](qs);
            }

            if (this.data.isFloor) {
                let reportParams = {
                    F_ID: this.data.tid || '0',
                    F_NAME: this.data.tName || '',
                    F_URL: this.data.url || '',
                    F_INDEX: this.data.tFindex || 1,
                    I_INDEX: (this.data.tIndex + 1) || 1,
                };

                event.emit('anchor-click', reportParams);
            }

            return global.router.goUrl(this.data.url);
        },
        
    }
});