1import Ctx from '../ctx.js' 2import Style from '../style.js' 3class Package extends Ctx { 4 constructor({ ctx, params, type, sequence, parent_attr_id, parent_hide_phone }) { 5 ctx = ctx || window.design.ctx 6 params = params || {} 7 super(ctx) 8 this.sequence = sequence || [] 9 this.current_hide_phone = parent_hide_phone || 0 10 this.dir = type 11 this.parent_attr_id = parent_attr_id || '' 12 this._initStructure(params) 13 if (params.renderActive) ctx.state.postCtxState.renderPackage = this 14 } 15 /** å¤çæå¡ç«¯åæ¬å°çæ°æ®å·®å¼ */ 16 _initStructure(params) { 17 if (typeof params === 'string') { 18 const ctx = this.getCtx() 19 const thisPackage = ctx.state.template.originalPackages[this.dir][params] 20 if (!thisPackage) console.log('sign ä¸åå¨:', params) 21 this.sign = params 22 this.style = thisPackage.style_sign 23 this.code = thisPackage.code || '' 24 this.hide_phone = thisPackage.hide_phone || 0 25 this.hide_pad = thisPackage.hide_pad || 0 26 this.hide_pc = thisPackage.hide_pc || 0 27 this.name_sign = params.name_sign || '' 28 this.initCloudData(thisPackage) 29 } else { 30 this.sign = params.sign || globalThis.Server.getSign() 31 this.style = params.style 32 this.code = params.code || '' 33 this.hide_phone = params.hide_phone || 0 34 this.hide_pad = params.hide_pad || 0 35 this.hide_pc = params.hide_pc || 0 36 this.name_sign = params.name_sign || '' 37 this.initCloudData(params, true) 38 } 39 // æ´æ°attr_id 40 this.attr_id = `${this.dir}-${this.sign}` 41 } 42 /** åå§åæ°æ® */ 43 async init(data) { 44 const ctx = this.getCtx() 45 // æ´æ°å ¶ä»å段 46 if (data) Object.keys(data).forEach(key => this[key] = data[key]) 47 // åå§åæ ·å¼ 48 this.initStyle() 49 // åå§åèªå·±ï¼ä¸è¬æ¯å¤çchildrenï¼ä½unit䏿¯ 50 await this.initSelf() 51 const name_sign = this.name_sign || '' 52 // ç¿»è¯åçåç§° 53 this.i18n_name = ctx.state.template.globalData?.html?.[name_sign]?.text || '' 54 // çå¾ åçº§å ¨é¨å®æ 55 if (this.children) await Promise.all(this.children.map(item => item.init())) 56 return this 57 } 58 /** åå§åæ ·å¼ */ 59 initStyle() { 60 const ctx = this.getCtx() 61 this.style = new Style(ctx, this.style, this.attr_id) 62 } 63 /** è·åèæ¯å¾æå è½½çå符串ï¼å¨main.jsä¸ä¼ä½¿ç¨ */ 64 getLazyBGString() { 65 function addSlash(str) { 66 return str.replace(/([\\'"])/g, "\\$1") 67 } 68 const ctx = this.getCtx() 69 var resJson = { 70 default: this.style.default.default['background-image'] ? 'url(' + this.style.default.default['background-image'] + ')' : '', 71 md: this.style.default.md['background-image'] ? 'url(' + this.style.default.md['background-image'] + ')' : '', 72 xl: this.style.default.xl['background-image'] ? 'url(' + this.style.default.xl['background-image'] + ')' : '', 73 } 74 let resString = '' 75 if (resJson.default || resJson.md || resJson.xl) { 76 if (ctx.state.site.prefix_domain) { 77 resJson.default = globalThis.Server.replaceImgDomain(resJson.default, ctx.state.site.prefix_domain, ctx.state.site.is_replace_domain) 78 resJson.md = globalThis.Server.replaceImgDomain(resJson.md, ctx.state.site.prefix_domain, ctx.state.site.is_replace_domain) 79 resJson.xl = globalThis.Server.replaceImgDomain(resJson.xl, ctx.state.site.prefix_domain, ctx.state.site.is_replace_domain) 80 } 81 if (resJson.default || resJson.md || resJson.xl) resString += ' lazy-type="background"' 82 if (resJson.default) resString += ` lazy-src="${addSlash(resJson.default)}"` 83 if (resJson.md) resString += ` lazy-md="${addSlash(resJson.md)}"` 84 if (resJson.xl) resString += ` lazy-xl="${addSlash(resJson.xl)}"` 85 } 86 87 const screenList = ['default', 'md', 'xl'] 88 const gradientAttrMap = { // ä½ 89 default: 1, 90 md: 2, 91 xl: 4, 92 } 93 const gradientValue = screenList.reduce((prev, screen) => { 94 const style = this.style.default?.[screen] 95 const gradient = style?.linear || style?.['--linear'] || '' 96 if (gradient && gradient.toLowerCase().indexOf('gradient') > -1) { 97 prev += gradientAttrMap[screen] 98 } 99 return prev 100 }, 0) 101 const gradientAttr = gradientValue ? ` gradient="${gradientValue}" ` : '' 102 resString += gradientAttr 103 return resString 104 } 105 /** è·ååè¡¨èæ¯å¾æå è½½çå符串*/ 106 getLazyListBGString(selector = '.unit-list__item-inner') { 107 const ctx = this.getCtx() 108 const style = this.style[selector] || { 109 default: { 'background-image': '' }, 110 md: { 'background-image': '' }, 111 xl: { 'background-image': '' } 112 } 113 const resJson = { 114 default: style.default['background-image'] || '', 115 md: style.md['background-image'] || '', 116 xl: style.xl['background-image'] || '' 117 } 118 let resString = '' 119 if (resJson.default || resJson.md || resJson.xl) { 120 if (ctx.state.site.prefix_domain) { 121 resJson.default = globalThis.Server.replaceImgDomain(resJson.default, ctx.state.site.prefix_domain, ctx.state.site.is_replace_domain) 122 resJson.md = globalThis.Server.replaceImgDomain(resJson.md, ctx.state.site.prefix_domain, ctx.state.site.is_replace_domain) 123 resJson.xl = globalThis.Server.replaceImgDomain(resJson.xl, ctx.state.site.prefix_domain, ctx.state.site.is_replace_domain) 124 } 125 resString += ` lazy-bg=` 126 if (resJson.default) resString += `default:${resJson.default};` 127 if (resJson.md) resString += `md:${resJson.md};` 128 if (resJson.xl) resString += `xl:${resJson.xl};` 129 resString += `` 130 } 131 return resString 132 } 133 /** è·åæ¾ç¤ºç¶æ */ 134 getDisplayStatus() { 135 let resString = '' 136 if (this.hide_phone) resString += ` hide-phone` 137 if (this.hide_pad) resString += ` hide-pad` 138 if (this.hide_pc) resString += ` hide-pc` 139 return resString 140 } 141 /** åå§åå级ï¼éè¦å¨ä¸åpackageä¸å好 */ 142 initSelf() { } 143 /** å¤çæ¥å£è¿åçå·®å¼ï¼éè¦å¨ä¸åpackageä¸å好 */ 144 initCloudData() { } 145} 146 147export default Package
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.