PageSourceSearch

https://www.meetion.es/src/package/block.js

js meetion.es collected 2026-10-04 20:35:47 UTC 3,237 bytes, 90 lines download raw bytes

1import Package from './package.js'
2import Module from './module.js'
3import HookBlock from '../hooks/block.js'
4import { PageConfig } from '../../config/index.js'
5
6class Block extends Package {
7  /**
8   * 构造函数
9   * @param {JSON} config
10   */
11  constructor({ ctx, params, type }) {
12    super({ ctx, params, type: 'block', sequence: [type] })
13    this.type = type
14  }
15  /** 处理接口返回的差异 */
16  initCloudData(thisPackage, isLocal) {
17    const ctx = this.getCtx()
18    const siteType = ctx.state.site.template_type
19    const positionIndex = siteType === 'b2b' ? 3 : 2
20    this.children = (isLocal ? thisPackage.module : null) || thisPackage.children || []
21    this.position = thisPackage.position || 2
22    this.position_index = thisPackage.position_index || positionIndex
23    if (thisPackage.type === 'header') {
24      this.float_top = thisPackage.float_top != undefined ? thisPackage.float_top : 1
25      this.bg_transparent = thisPackage.bg_transparent != undefined ? thisPackage.bg_transparent : 1
26
27      this.float_top_inside = thisPackage.float_top_inside != undefined ? thisPackage.float_top_inside : 0
28      this.bg_transparent_inside = thisPackage.bg_transparent_inside != undefined ? thisPackage.bg_transparent_inside : 0
29      this.customer_inside = thisPackage.customer_inside != undefined ? thisPackage.customer_inside : 0
30      this.float_column = thisPackage.float_column != undefined ? thisPackage.float_column : []
31      this.special_column = thisPackage.special_column != undefined ? thisPackage.special_column : []
32    } else {
33      this.position = thisPackage.position || 0
34      this.position_index = thisPackage.position_index || 0
35    }
36  }
37  /** 把子级都实例化 */
38  async initSelf() {
39    this.initHooks()
40    // 根据页面类型匹配上面的规则
41    const ctx = this.getCtx()
42    const pageType = ctx.state.page.page_type
43    switch (this.type) {
44      case 'header':
45        this.hide = PageConfig[pageType].allowBlockHeader ? 0 : 1
46        break
47      case 'breadcrumb':
48        this.hide = PageConfig[pageType].allowBlockBreadcrumb ? 0 : 1
49        break
50      case 'info':
51        this.hide = PageConfig[pageType].allowBlockInfo ? 0 : 1
52        break
53      case 'main':
54        this.hide = PageConfig[pageType].allowBlockMain ? 0 : 1
55        break
56      case 'extend':
57        this.hide = PageConfig[pageType].allowBlockExtend ? 0 : 1
58        break
59      case 'footer':
60        this.hide = PageConfig[pageType].allowBlockFooter ? 0 : 1
61        break
62      case 'copyright':
63        this.hide = PageConfig[pageType].allowBlockCopyright ? 0 : 1
64        break
65    }
66    if (this.hide) this.children = []
67    let i = 0
68    this.children = this.children?.map(signOrData => {
69      try {
70        const sequence = [...this.sequence]
71        sequence.push(i++)
72        return new Module({ctx, params: signOrData, sequence, parent_attr_id: this.attr_id})
73      } catch (err) {
74        ctx.state.error = {
75          code: err.code,
76          message: err.message,
77          stack: err.stack,
78        }
79      }
80    }).filter(item => item)
81  }
82  /** 初始化钩子函数 */
83  initHooks() {
84    const ctx = this.getCtx()
85    this.hook = new HookBlock(ctx, {}, this)
86  }
87}
88
89
90export default Block

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.