NoctisHsu
1/17/2017 - 10:15 AM

pageValue.ts

/// <reference path="../../Scripts/typings/angularjs/angular.d.ts"/>

namespace NineYi.Mall.Values {
    import PageNameEnum = NineYi.Mall.Models.PageNameEnum;
    export class PageValue {
        /**
         * 當前頁面Enum
         */
        public CurrentPage: PageNameEnum;
        /**
         * 當前頁面名稱
         */
        public CurrentPageName: string;

        /**
         * 是否為Sigle sign-on domain (ex: service.91app.com)
         */
        public IsSsoDomain: boolean;

        constructor() {
            let pathName = window.location.pathname;
            switch (true) {
                // 首頁
                case (/(\/v2\/official\/$)|(\/v2\/official$)|^$|(^\/$)|(\/v2\/official\/Index$)|(\/v2\/official\/Index\/)/ig)
                    .test(pathName) :
                    this.CurrentPage = PageNameEnum.OfficailIndex;
                    this.CurrentPageName = '首頁';
                    break;
                // 分類頁
                case (/\/v2\/official\/salepagecategory\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.SalePageCategory;
                    this.CurrentPageName = '小分類頁';
                    break;
                // 商品頁
                case (/\/salepage\/index\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.SalePageIndex;
                    this.CurrentPageName = '商品頁';
                    break;
                // 熱銷排行
                case (/\/shop\/hotSaleRanking\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.HotSaleRanking;
                    this.CurrentPageName = '銷售排行';
                    break;
                // 最新商品
                case (/\/v2\/official\/newestSalePage\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.NewestSalePage;
                    this.CurrentPageName = '最新商品頁';
                    break;
                // 折扣活動列表頁
                case (/\/promotion\/list\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.PromotionList;
                    this.CurrentPageName = '折扣活動列表頁';
                    break;
                // 折扣活動詳細頁
                case (/\/promotion\/detail\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.PromotionDetail;
                    this.CurrentPageName = '折扣活動';
                    break;
                // 折價券列表頁
                case (/\/ecoupon\/list\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.ECouponList;
                    this.CurrentPageName = '折價券列表頁';
                    break;
                // 折價券詳細頁
                case (/\/ecoupon\/detail\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.ECouponDetail;
                    this.CurrentPageName = '折價券';
                    break;
                // 折價券使用說明頁
                case (/\/ecoupon\/howToUse\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.ECouponHowToUse;
                    this.CurrentPageName = '折價券使用說明';
                    break;
                // 門市優惠券列表頁
                case (/\/coupon\/list\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.CouponList;
                    this.CurrentPageName = '門市優惠券列表';
                    break;
                // 門市優惠券明細頁
                case (/\/coupon\/detail\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.CouponDetail;
                    this.CurrentPageName = '門市優惠';
                    break;
                // 搜尋頁
                case (/\/search\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.SearchIndex;
                    this.CurrentPageName = '搜尋結果頁';
                    break;
                // 購物車頁
                case (/\/v2\/ShoppingCart*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.ShoppingCartIndex;
                    this.CurrentPageName = '購物車頁';
                    break;
                // 結帳付款頁
                case (/\/v2\/pay\/index\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.PayIndex;
                    this.CurrentPageName = '結帳付款頁';
                    break;
                // 結帳完成頁
                case (/\/v2\/pay\/finish\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.PayFinish;
                    this.CurrentPageName = '結帳完成頁';
                    break;

                case (/\/v2\/shop\/InfoModuleList\/*/ig).test(pathName):
                    if (window.location.hash === "#/AlbumList") {
                        this.CurrentPage = PageNameEnum.AlbumList;
                        this.CurrentPageName = '相簿列表頁';
                    }
                    else if (window.location.hash === "#/ArticleList") {
                        this.CurrentPage = PageNameEnum.ArticleList;
                        this.CurrentPageName = '文章列表頁';
                    }
                    else if (window.location.hash === "#/VideoList") {
                        this.CurrentPage = PageNameEnum.VideoList;
                        this.CurrentPageName = '影片列表頁';
                    }
                    break;

                // 圖文模組頁
                case (/\/Article\/Detail\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.ArticleDetail;
                    this.CurrentPageName = '圖文模組頁';
                    break;
                // 影音模組頁
                case (/\/Video\/Detail\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.VideoDetail;
                    this.CurrentPageName = '影音模組頁';
                    break;

                // 相簿模組頁
                case (/\/Album\/Detail\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.AlbumDetail;
                    this.CurrentPageName = '相簿模組頁';
                    break;

                // 活動頁
                case (/\/v2\/activity\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.ActivityIndex;
                    this.CurrentPageName = '活動頁';
                    break;
                case (/\/Shop\/StoreList\/*/ig).test(pathName):
                    this.CurrentPage = PageNameEnum.ShopStoreList;
                    this.CurrentPageName = '門市列表頁';
                    break;
                default:
                    break;
            }

            this.IsSsoDomain = (/^((service.91app+)\.tw\.(dev|qa|pp)|(service.91app.com))$/ig).test(
                window.location.hostname)
        }

    }

    angular.module("NineYi.Mall.Values")
        .value('PageValue', new PageValue());
}