UNPKG

17.5 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = undefined;
7
8var _localeProvider = require('jdcloudui/lib/locale-provider');
9
10var _localeProvider2 = _interopRequireDefault(_localeProvider);
11
12var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
13
14var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
15
16var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
17
18var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
19
20var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
21
22var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
23
24var _createClass2 = require('babel-runtime/helpers/createClass');
25
26var _createClass3 = _interopRequireDefault(_createClass2);
27
28var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
29
30var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
31
32var _inherits2 = require('babel-runtime/helpers/inherits');
33
34var _inherits3 = _interopRequireDefault(_inherits2);
35
36var _class, _temp; //链接跳转,相当于a标签
37
38
39// 国际化中文
40
41
42require('jdcloudui/lib/locale-provider/style');
43
44var _react = require('react');
45
46var _react2 = _interopRequireDefault(_react);
47
48var _propTypes = require('prop-types');
49
50var _propTypes2 = _interopRequireDefault(_propTypes);
51
52var _reactRouter = require('react-router');
53
54var _Header = require('./Header/Header');
55
56var _Header2 = _interopRequireDefault(_Header);
57
58var _Sider = require('./Sider/Sider');
59
60var _Sider2 = _interopRequireDefault(_Sider);
61
62var _TopTools = require('../TopTools/TopTools');
63
64var _TopTools2 = _interopRequireDefault(_TopTools);
65
66var _reactHelmet = require('react-helmet');
67
68var _reactHelmet2 = _interopRequireDefault(_reactHelmet);
69
70var _ApiClient = require('../../apiClient/ApiClient');
71
72var _ApiClient2 = _interopRequireDefault(_ApiClient);
73
74require('./style/shop.css');
75
76var _zh_CN = require('jdcloudui/lib/locale-provider/zh_CN');
77
78var _zh_CN2 = _interopRequireDefault(_zh_CN);
79
80var _moment = require('moment');
81
82var _moment2 = _interopRequireDefault(_moment);
83
84function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
85
86_moment2.default.locale('zh-cn');
87
88var ms = [{
89 id: 1,
90 name: "首页",
91 href: "http://shop.hnc.jcloudec.com/shop-view/home",
92 target: "_self",
93 children: [{
94 id: 11,
95 name: "商品管理",
96 icon: "cgs",
97 children: [{
98 id: 111,
99 name: "经营类目",
100 href: "http://shop.hnc.jcloudec.com/item-shop-view/goods-manage/category",
101 target: "_self"
102 }, {
103 id: 112,
104 name: "经营品牌",
105 href: "http://shop.hnc.jcloudec.com/item-shop-view/goods-manage/brand",
106 target: "_self"
107 }]
108 }, {
109 id: 12,
110 name: "商品发布",
111 icon: "cgs",
112 children: [{
113 id: 121,
114 name: "选择供货商品",
115 href: "http://shop.hnc.jcloudec.com/item-shop-view/selectgoods",
116 target: "_self"
117 }, {
118 id: 122,
119 name: "商品信息管理",
120 href: "http://shop.hnc.jcloudec.com/item-shop-view/iteminfo",
121 target: "_self"
122 }, {
123 id: 123,
124 name: "提交新商品",
125 href: "http://shop.hnc.jcloudec.com/item-shop-view/goods-release",
126 target: "_self"
127 }]
128 }, {
129 id: 13,
130 name: "物流服务",
131 icon: "cgs",
132 children: [{
133 id: 131,
134 name: "地址管理",
135 href: "http://shop.hnc.jcloudec.com/user-shop-view/supplier/address",
136 target: "_self"
137 }]
138 }]
139}, {
140 id: 2,
141 name: "账号管理",
142 children: [{
143 id: 21,
144 name: "账号管理",
145 icon: "cgs",
146 children: [{
147 id: 211,
148 name: "账号信息",
149 href: "http://shop.hnc.jcloudec.com/user-shop-view/accountmanage/accountInfo",
150 target: "_self"
151 }, {
152 id: 212,
153 name: "账号安全",
154 href: "http://shop.hnc.jcloudec.com/user-shop-view/accountmanage/accountSecurity",
155 target: "_self"
156 }]
157 }]
158}, {
159 id: 3,
160 name: "订单管理",
161 children: [{
162 id: 31,
163 name: "订单管理",
164 icon: "xx",
165 children: [{
166 id: 311,
167 name: "订单管理",
168 href: "http://shop.hnc.jcloudec.com/order-shop-view/order/list",
169 target: "_self"
170 }, {
171 id: 312,
172 name: "销售区域设置",
173 href: "http://shop.hnc.jcloudec.com/order-shop-view/salearea",
174 target: "_self"
175 }, {
176 id: 313,
177 name: "换货订单",
178 href: "http://shop.hnc.jcloudec.com/customer-service-shop-view/exchange/grid",
179 target: "_self"
180 }, {
181 id: 314,
182 name: "退换货记录",
183 href: "http://shop.hnc.jcloudec.com/customer-service-shop-view/returnexchangerecord/grid",
184 target: "_self"
185 }]
186 }]
187}, {
188 id: 5,
189 name: "财务管理",
190 children: [{
191 id: 51,
192 name: "会员资金账户",
193 href: "http://shop.hnc.jcloudec.com/finance-shop-view/memberFinanceAccount",
194 target: "_self"
195 }, {
196 id: 52,
197 name: "结算管理",
198 href: "http://shop.hnc.jcloudec.com/finance-shop-view/settlement/grid",
199 target: "_self"
200 }]
201}];
202var Shop = (_temp = _class = function (_Component) {
203 (0, _inherits3.default)(Shop, _Component);
204
205 function Shop(props, context) {
206 (0, _classCallCheck3.default)(this, Shop);
207
208 var _this = (0, _possibleConstructorReturn3.default)(this, (Shop.__proto__ || (0, _getPrototypeOf2.default)(Shop)).call(this, props, context));
209
210 _this.state = {
211 menus: [],
212 icon: "",
213 logo: ''
214 };
215 _this.buyerDomain = '/';
216 _this.resource = {};
217 return _this;
218 }
219
220 //获取买家域名
221
222
223 (0, _createClass3.default)(Shop, [{
224 key: 'getBuyerDomainForSubcount',
225 value: function getBuyerDomainForSubcount() {
226 var _this2 = this;
227
228 var client = new _ApiClient2.default();
229 client.get('/passport/logout').then(function (res) {
230 if (res.code == 0 && res.data) {
231 res.data.map(function (_item) {
232 if (_item.domainType == 2) {
233 _this2.buyerDomain = _item.domain;
234 var result = _this2.reformData(_this2.resource);
235 _this2.setState({
236 menus: result
237 });
238 }
239 });
240 }
241 }, function (err) {});
242 }
243
244 // 根据name获取cookie值
245
246 }, {
247 key: 'getCookieByArray',
248 value: function getCookieByArray(name) {
249 if (typeof document !== 'undefined') {
250 var cookies = document.cookie.split(';');
251 var c;
252 for (var i = 0; i < cookies.length; i++) {
253 c = cookies[i].split('=');
254 if (c[0].replace(' ', '') == name) {
255 return c[1];
256 }
257 }
258 } else {
259 return null;
260 }
261 }
262 //------------------动态获取菜单begin-------------------------------------
263
264 }, {
265 key: 'shopMenuSearch',
266 value: function shopMenuSearch() {
267 var _this3 = this;
268
269 var client = new _ApiClient2.default();
270 var form = null;
271 client.get('/authority-service/mall/resource/queryResourceMenuBySellerId', { params: { shopType: this.getCookieByArray('shopType') ? this.getCookieByArray('shopType') : '' } }).then(function (res) {
272 if (res.code == 0 && res.data) {
273 _this3.resource = res.data;
274 var result = _this3.reformData(res.data);
275 _this3.setState({
276 menus: result
277 });
278 }
279 }, function (err) {});
280 }
281 }, {
282 key: 'reformData',
283 value: function reformData(data) {
284 var result = [];
285 if (data && data.length) {
286 for (var ia = 0; ia < data.length; ++ia) {
287 var tmp = this.reformUnit(data[ia]);
288 if (tmp) {
289 result.push(tmp);
290 }
291 }
292 }
293 return result;
294 }
295 }, {
296 key: 'reformUnit',
297 value: function reformUnit(data) {
298 var unit = { id: '', name: '', href: '', target: '', children: [] };
299 unit.id = data.id + '';
300 unit.name = data.name;
301 if (data.name == '子账号管理' && data.url && data.url.indexOf('buyer.') == -1) {
302 unit.href = '//' + this.buyerDomain + data.url;
303 unit.target = '_blank';
304 } else {
305 unit.href = data.url;
306 unit.target = data.target ? data.target : '_self';
307 }
308 unit.icon = data.icon;
309 if (data && data.url && data.url == '/subaccount-buyer-view/subaccountmanage') {
310 if (data && data.children && data.children.length > 0) {
311 if (this.buyerDomain == '/') {
312 return false;
313 } else {
314 unit.href = '//' + this.buyerDomain + data.children[0].url;
315 }
316 }
317 unit.target = '_blank';
318 delete unit['children'];
319 return unit;
320 }
321 if (data && data.children && data.children.length > 0) {
322 for (var ib = 0; ib < data.children.length; ++ib) {
323 var tmp = this.reformUnit(data.children[ib]);
324 if (tmp) {
325 unit.children.push(tmp);
326 }
327 }
328 } else {
329 delete unit['children'];
330 }
331 return unit;
332 }
333 //------------------动态获取菜单end-------------------------------------
334 //------------------获取ICON--------------------------------------------
335
336 }, {
337 key: 'getWebsiteConfig',
338 value: function getWebsiteConfig() {
339 var _this4 = this;
340
341 var client = new _ApiClient2.default();
342 client.get('/platform-service/mallInfo/getMallInfo').then(function (res) {
343 if (res.code == 0 && res.data) {
344 _this4.setState({ icon: res.data.icon, logo: res.data.userLogo });
345 }
346 }, function (err) {});
347 }
348 //----------------------------------------------------------------------
349
350 }, {
351 key: 'componentWillMount',
352 value: function componentWillMount() {
353 this.getBuyerDomainForSubcount();
354 this.shopMenuSearch();
355 this.getWebsiteConfig();
356 this.minHeight = typeof window !== 'undefined' ? document.body.clientHeight - 64 : 580;
357 this.location = typeof window !== 'undefined' ? window.location.href : "";
358 this.referer = typeof document !== 'undefined' ? document.referrer : "";
359 }
360 }, {
361 key: 'getHref',
362 value: function getHref(o) {
363 if (o && o.length) {
364 for (var i = 0; i < o.length; i++) {
365 var menu = o[i];
366 if (menu.href && menu.href != "") {
367 return menu.href;
368 } else if (menu.children && menu.children.length) {
369 return this.getHref(menu.children);
370 } else {
371 return "";
372 }
373 }
374 } else {
375 return "";
376 }
377 }
378 }, {
379 key: 'horizontalMenu',
380 value: function horizontalMenu(o) {
381 var _this5 = this;
382
383 var horizontalMenu = [];
384 if (o && o.length && o.length > 0) {
385 o.map(function (menu) {
386 var children = menu.children,
387 rest = (0, _objectWithoutProperties3.default)(menu, ['children']);
388
389 rest.href = rest.href && rest.href != "" ? rest.href : _this5.getHref(children);
390 horizontalMenu.push(rest);
391 });
392 }
393 return horizontalMenu;
394 }
395 }, {
396 key: 'urlMatch',
397 value: function urlMatch(location, href) {
398 //href: 接口返回的全路径
399 //location: menuUrl
400 //menuUrl优先匹配
401 if (location != '' && href && href != '') {
402 if (href.indexOf('//') > 0) {
403 if (location == href.substring(href.replace('//', '~%').indexOf('/'))) {
404 return true;
405 }
406 } else {
407 if (location == href) {
408 return true;
409 }
410 }
411 }
412 var finalLocation = '';
413 if (location) {
414 var result = String(location).split('.com');
415 if (result && result.length && result[1]) {
416 var path = result[1];
417 var tmp = path.split('?');
418 if (tmp && tmp[0]) {
419 finalLocation = tmp[0];
420 if (finalLocation == href) {
421 return true;
422 }
423 }
424 }
425 }
426 return false;
427 }
428 }, {
429 key: 'verticalMenu',
430 value: function verticalMenu(o, location) {
431 var subMenu = [];
432 var hKey = 0;
433 var vKey = 0;
434 var vName = "";
435 var openKey = [];
436 if (o && o.length && o.length > 0) {
437 for (var i = 0; i < o.length; i++) {
438 var menu = o[i];
439 if (menu.href && menu.href != "" && this.urlMatch(location, menu.href)) {
440 subMenu = menu.children;
441 hKey = menu.id;
442 var tmpOpenKey = [];
443 for (var q in menu.children) {
444 tmpOpenKey.push(menu.children[q].id + '');
445 }
446 openKey = tmpOpenKey;
447 } else if (menu.children && menu.children.length) {
448 for (var j = 0; j < menu.children.length; j++) {
449 var vMenu = menu.children[j];
450 if (vMenu.href && vMenu.href != "" && this.urlMatch(location, vMenu.href)) {
451 subMenu = menu.children;
452 hKey = menu.id;
453 vKey = vMenu.id;
454 vName = vMenu.name;
455 } else if (vMenu.children && vMenu.children.length) {
456 for (var n = 0; n < vMenu.children.length; n++) {
457 var sMenu = vMenu.children[n];
458 if (sMenu.href && sMenu.href != "" && this.urlMatch(location, sMenu.href)) {
459 subMenu = menu.children;
460 hKey = menu.id;
461 vKey = sMenu.id;
462 vName = sMenu.name;
463 openKey.push(vMenu.id);
464 }
465 }
466 }
467 }
468 }
469 }
470 }
471 return { subMenu: subMenu, hKey: hKey, openKey: openKey, vKey: vKey, vName: vName };
472 }
473 /*verticalMenu(o,location) {
474 var subMenu = [];
475 var hKey = 0;
476 var vKey = 0;
477 var openKey = 0;
478 for(var i = 0; i < o.length; i++) {
479 var menu = o[i];
480 if(menu.href&&menu.href!=""&&location.indexOf(menu.href)!=-1) {
481 subMenu=[];
482 hKey = menu.id;
483 }else if(menu.children&&menu.children.length){
484 for(var j = 0; j < menu.children.length; j++) {
485 var vMenu = menu.children[j];
486 if(vMenu.href&&vMenu.href!=""&&location.indexOf(vMenu.href)!=-1) {
487 subMenu = menu.children;
488 hKey = menu.id;
489 }else if(vMenu.children&&vMenu.children.length) {
490 for(var n = 0; n < vMenu.children.length; n++) {
491 var sMenu = vMenu.children[n];
492 if(sMenu.href&&sMenu.href!=""&&location.indexOf(sMenu.href)!=-1) {
493 subMenu = menu.children;
494 hKey = menu.id;
495 vKey = sMenu.id;
496 openKey=vMenu.id;
497 }
498 }
499 }
500 }
501 }
502 }
503 return {subMenu,hKey,openKey,vKey}
504 }*/
505
506 }, {
507 key: 'render',
508 value: function render() {
509 var _props$menus = this.props.menus,
510 menus = _props$menus === undefined ? ms : _props$menus;
511
512 var horizontalMenu = this.horizontalMenu(this.state.menus);
513 var menuUrl = this.props.menuUrl || this.props.children && this.props.children.props && this.props.children.props.route && this.props.children.props.route.menuUrl;
514 var verticalMenu = { subMenu: [], hKey: '0', openKey: '0', vKey: [] };
515 if (menuUrl) {
516 verticalMenu = this.verticalMenu(this.state.menus, menuUrl);
517 } else {
518 verticalMenu = this.verticalMenu(this.state.menus, this.location);
519 }
520 if (verticalMenu.subMenu && verticalMenu.subMenu.length && verticalMenu.subMenu.length == 0) {
521 verticalMenu = this.verticalMenu(this.state.menus, this.referer || "");
522 }
523 var _verticalMenu = verticalMenu,
524 hKey = _verticalMenu.hKey,
525 vName = _verticalMenu.vName,
526 rest = (0, _objectWithoutProperties3.default)(_verticalMenu, ['hKey', 'vName']);
527
528 return _react2.default.createElement(
529 _localeProvider2.default,
530 { locale: _zh_CN2.default },
531 _react2.default.createElement(
532 'div',
533 null,
534 _react2.default.createElement(
535 _reactHelmet2.default,
536 null,
537 _react2.default.createElement(
538 'title',
539 null,
540 vName
541 ),
542 _react2.default.createElement('link', { rel: 'icon', href: this.state.icon, mce_href: this.state.icon, type: 'image/x-icon' })
543 ),
544 _react2.default.createElement(_TopTools2.default, null),
545 _react2.default.createElement(_Header2.default, { menus: horizontalMenu, selectKey: hKey, logo: this.state.logo }),
546 _react2.default.createElement(
547 'div',
548 { className: 'shop-framework-body-container' },
549 _react2.default.createElement(
550 'div',
551 { className: 'shop-framework-body-container-left' },
552 _react2.default.createElement(_Sider2.default, rest)
553 ),
554 _react2.default.createElement(
555 'div',
556 { className: 'shop-framework-body-container-right', style: { minHeight: this.minHeight + "px" } },
557 this.props.children
558 )
559 )
560 )
561 );
562 }
563 }]);
564 return Shop;
565}(_react.Component), _class.propTypes = {
566 children: _propTypes2.default.object.isRequired
567}, _temp);
568exports.default = Shop;
569module.exports = exports['default'];
570//# sourceMappingURL=Shop.js.map
\No newline at end of file