@@ -282,57 +282,61 @@ export class FormPreviewer {
282282 // Отдельно обрабатываем случаи когда общие картинки сохранены в формате zip
283283 const regex = new RegExp ( `${ this . confPath } /CommonPictures/(%|[A-Za-z]|[0-9])+/Ext/Picture/Picture.png` , "g" ) ;
284284 const picArray = html . match ( regex ) ;
285- picArray . forEach ( ( img : string ) => {
286- if ( ! fs . existsSync ( img ) ) {
287- const zipName = decodeURI ( img . replace ( '.png' , '.zip' ) ) ;
288- if ( fs . existsSync ( zipName ) ) {
289- const zip = new AdmZip ( zipName ) ;
290- const zipEntries = zip . getEntries ( ) ;
291- const picturePng = zipEntries . find ( ( entry ) => entry . name === 'Picture.png' ) ;
292- const pictureXml = zipEntries . find ( ( entry ) => entry . name === 'manifest.xml' ) ;
293- if ( picturePng && pictureXml ) {
294- const buffer = zip . readFile ( picturePng ) ;
295- const textXml = zip . readAsText ( pictureXml ) ;
296- if ( buffer ) {
297- const parser = new XMLParser ( {
298- ignoreAttributes : false ,
299- } ) ;
300- const pictureParsed = parser . parse ( textXml ) ;
301- const pictureVariant = pictureParsed [ 'Picture' ] [ 'PictureVariant' ]
302- . find ( ( variant : any ) => variant [ '@_name' ] == 'Picture.png' && variant [ '@_interfaceVariant' ] == 'version8_2' ) ;
285+ if ( picArray ) {
286+ picArray . forEach ( ( img : string ) => {
287+ if ( ! fs . existsSync ( img ) ) {
288+ const zipName = decodeURI ( img . replace ( '.png' , '.zip' ) ) ;
289+ if ( fs . existsSync ( zipName ) ) {
290+ const zip = new AdmZip ( zipName ) ;
291+ const zipEntries = zip . getEntries ( ) ;
292+ const picturePng = zipEntries . find ( ( entry ) => entry . name === 'Picture.png' ) ;
293+ const pictureXml = zipEntries . find ( ( entry ) => entry . name === 'manifest.xml' ) ;
294+ if ( picturePng && pictureXml ) {
295+ const buffer = zip . readFile ( picturePng ) ;
296+ const textXml = zip . readAsText ( pictureXml ) ;
297+ if ( buffer ) {
298+ const parser = new XMLParser ( {
299+ ignoreAttributes : false ,
300+ } ) ;
301+ const pictureParsed = parser . parse ( textXml ) ;
302+ const pictureVariant = pictureParsed [ 'Picture' ] [ 'PictureVariant' ]
303+ . find ( ( variant : any ) => variant [ '@_name' ] == 'Picture.png' && variant [ '@_interfaceVariant' ] == 'version8_2' ) ;
303304
304- html = html . replace ( img + '">' ,
305- `data:image/png;base64,${ Buffer . from ( buffer ) . toString ( 'base64' ) } " style="width: ${ pictureVariant [ '@_glyphWidth' ] } px; height: ${ pictureVariant [ '@_glyphHeight' ] } px;">` ) ;
305+ html = html . replace ( img + '">' ,
306+ `data:image/png;base64,${ Buffer . from ( buffer ) . toString ( 'base64' ) } " style="width: ${ pictureVariant [ '@_glyphWidth' ] } px; height: ${ pictureVariant [ '@_glyphHeight' ] } px;">` ) ;
307+ }
306308 }
307309 }
308310 }
309- }
310- } ) ;
311- // Атрибуты
312- // Типовые
313- // Справочники
314- html = html . replace ( `${ mainAttribute . $_name } .Code` , 'Код' ) ;
315- html = html . replace ( `${ mainAttribute . $_name } .Description` , 'Наименование' ) ;
316- html = html . replace ( `${ mainAttribute . $_name } .Parent` , 'Входит в группу' ) ;
317- // Документы
318- html = html . replace ( `${ mainAttribute . $_name } .Number` , 'Номер' ) ;
319- html = html . replace ( `${ mainAttribute . $_name } .Date` , 'Дата' ) ;
320- // Прочие
321- childObjects . Attribute ?. forEach ( ( attr ) => {
322- html = html . replaceAll ( `${ mainAttribute . $_name } .${ attr [ 'Properties' ] [ 'Name' ] } ` ,
323- attr [ 'Properties' ] [ 'Synonym' ] [ 'v8:item' ] [ 'v8:content' ] ) ;
324- } ) ;
325- // Табличные части
326- childObjects . TabularSection ?. forEach ( ( tab : any ) => {
327- // Атрибуты табличных частей
311+ } ) ;
312+ }
313+ if ( mainAttribute ) {
314+ // Атрибуты
328315 // Типовые
329- html = html . replaceAll ( `${ mainAttribute . $_name } .${ tab [ 'Properties' ] [ 'Name' ] } .LineNumber` , 'N' ) ;
330- tab [ 'ChildObjects' ] [ 'Attribute' ] . forEach ( ( attr : any ) => {
331- // Прочие
332- html = html . replaceAll ( `${ mainAttribute . $_name } .${ tab [ 'Properties' ] [ 'Name' ] } .${ attr [ 'Properties' ] [ 'Name' ] } ` ,
333- `${ attr [ 'Properties' ] [ 'Synonym' ] [ 'v8:item' ] [ 'v8:content' ] } ` ) ;
316+ // Справочники
317+ html = html . replace ( `${ mainAttribute . $_name } .Code` , 'Код' ) ;
318+ html = html . replace ( `${ mainAttribute . $_name } .Description` , 'Наименование' ) ;
319+ html = html . replace ( `${ mainAttribute . $_name } .Parent` , 'Входит в группу' ) ;
320+ // Документы
321+ html = html . replace ( `${ mainAttribute . $_name } .Number` , 'Номер' ) ;
322+ html = html . replace ( `${ mainAttribute . $_name } .Date` , 'Дата' ) ;
323+ // Прочие
324+ childObjects . Attribute ?. forEach ( ( attr ) => {
325+ html = html . replaceAll ( `${ mainAttribute . $_name } .${ attr [ 'Properties' ] [ 'Name' ] } ` ,
326+ attr [ 'Properties' ] [ 'Synonym' ] [ 'v8:item' ] [ 'v8:content' ] ) ;
334327 } ) ;
335- } ) ;
328+ // Табличные части
329+ childObjects . TabularSection ?. forEach ( ( tab : any ) => {
330+ // Атрибуты табличных частей
331+ // Типовые
332+ html = html . replaceAll ( `${ mainAttribute . $_name } .${ tab [ 'Properties' ] [ 'Name' ] } .LineNumber` , 'N' ) ;
333+ tab [ 'ChildObjects' ] [ 'Attribute' ] . forEach ( ( attr : any ) => {
334+ // Прочие
335+ html = html . replaceAll ( `${ mainAttribute . $_name } .${ tab [ 'Properties' ] [ 'Name' ] } .${ attr [ 'Properties' ] [ 'Name' ] } ` ,
336+ `${ attr [ 'Properties' ] [ 'Synonym' ] [ 'v8:item' ] [ 'v8:content' ] } ` ) ;
337+ } ) ;
338+ } ) ;
339+ }
336340
337341 html = html . replace ( '<script></script>' , `
338342 <script>
0 commit comments