Best JavaScript code snippet using playwright-internal
ActionParser.js
Source:ActionParser.js
1import Actions from '@/models/skill/index'2function targetAnalyzer (action, dependAction) {3 const targetAssignmentMap = {4 1: ['enemy', 'ãææ¹ã'],5 2: ['ally', 'ãå·±æ¹ã'],6 3: ['both', 'ãåæ¹ã'],7 default: ['unknown', '']8 }9 const targetTypeMap = {10 0: ['zero', 'ãæè¿ç$1$2ã'],11 1: ['none', 'ã被ä¸ä¸ä¸ªææå½±åçææè¿ç$1$2ã'],12 2: ['random', 'ãéæº$1ã'],13 3: ['near', Number(action.target_number) === 0 || Number(action.target_count) === 1 ? 'ãæè¿ç$1$2ã' : 'ã$2è¿ç$1ã'],14 4: ['far', 'ãæè¿ç$1$2ã'],15 5: ['hpAscending', 'ã HP ç¾åæ¯æä½ç$1$2ã'],16 6: ['hpDescending', 'ã HP ç¾åæ¯æé«ç$1$2ã'],17 7: ['self', 'ãèªèº«ã'],18 8: ['randomOnce', 'ãé¦æ¬¡éæºã'],19 9: ['forward', 'ãæé åç$1$2ã'],20 10: ['backward', 'ãæé åç$1$2ã'],21 11: ['absolute', 'ãèå´å
çç®æ ã'],22 12: ['tpDescending', 'ã TP æå¤ç$1$2ã'],23 13: ['tpAscending', 'ã TP æå°ç$1$2ã'],24 14: ['atkDescending', 'ãç©çæ»å»åæé«ç$1$2ã'],25 15: ['atkAscending', 'ãç©çæ»å»åæä½ç$1$2ã'],26 16: ['magicSTRDescending', 'ãéæ³æ»å»åæé«ç$1$2ã'],27 17: ['magicSTRAscending', 'ãéæ³æ»å»åæä½ç$1$2ã'],28 18: ['summon', 'ã$1éä»ã'],29 19: ['tpReducing', 'ã TP æå°ç$1$2ã'],30 20: ['physics', 'ã$1ç©çç³»ã'],31 21: ['magic', 'ã$1æ³ç³»ã'],32 22: ['allSummonRandom', 'ãéæºéä»ã'],33 23: ['selfSummonRandom', 'ãèªå·±çéæºéä»ã'],34 24: ['boss', 'ã$1é¦é¢çº§ã'],35 25: ['hpAscendingOrNear', 'ã HP ç¾åæ¯æä½ç$1$2ã'],36 26: ['hpDescendingOrNear', 'ã HP ç¾åæ¯æé«ç$1$2ã'],37 27: ['tpDescendingOrNear', 'ã TP æå¤ç$1$2ã'],38 28: ['tpAscendingOrNear', 'ã TP æå°ç$1$2ã'],39 29: ['atkDescendingOrNear', 'ãç©çæ»å»åæé«ç$1$2ã'],40 30: ['atkAscendingOrNear', 'ãç©çæ»å»åæä½ç$1$2ã'],41 31: ['magicSTRDescendingOrNear', 'ãéæ³æ»å»åæé«ç$1$2ã'],42 32: ['magicSTRAscendingOrNear', 'ãéæ³æ»å»åæä½ç$1$2ã'],43 33: ['shadow', 'ã$1æå½±ã'],44 34: ['nearWithoutOwner', 'ãé¤èªå·±å¤æè¿ç$1$2ã'],45 default: ['unknown', '']46 }47 const targetCountMap = {48 0: ['zero', ''],49 1: ['one', 'ä¸ä¸ª'],50 2: ['two', '两个'],51 3: ['three', 'ä¸ä¸ª'],52 4: ['four', 'å个'],53 99: ['all', 'å
¨é¨'],54 default: ['unknown', '']55 }56 const targetNumberMap = {57 0: ['first', '第ä¸ä½'],58 1: ['second', '第äºä½'],59 2: ['third', '第ä¸ä½'],60 3: ['fourth', '第åä½'],61 4: ['fifth','第äºä½'],62 default: ['unknown', '']63 }64 const targetRangeMap = {65 infinite: [-1, -1],66 zero: [0, 0],67 finite: [1, 2159],68 all: [2160, Number.MAX_SAFE_INTEGER]69 }70 const targetAreaMap = {71 1: ['front', 'ãåæ¹ã'],72 2: ['frontAndBack', 'ãåæ¹ååæ¹ã'],73 3: ['all', 'ãå
¨ä½ã'],74 default: ['unknown', '']75 }76 const targetAssignment = targetAssignmentMap[Number(action.target_assignment)] || targetAssignmentMap.default77 const targetType = targetTypeMap[Number(action.target_type)] || targetTypeMap.default78 const targetCount = targetCountMap[Number(action.target_count)] || targetCountMap.default79 const targetNumber = targetNumberMap[Number(action.target_number)] || targetNumberMap.default80 const targetRange = Object.keys(targetRangeMap).filter(range => Number(action.target_range) >= targetRangeMap[range][0] && Number(action.target_range) <= targetRangeMap[range][1])[0] || 'unknown'81 const targetArea = targetAreaMap[Number(action.target_area)] || targetAreaMap.default82 const hasRelationPhrase = !['self', 'absolute'].includes(targetType[0])83 const hasCountPhrase = !['self', 'none', 'zero'].includes(targetType[0])84 const hasRangePhrase = targetRange === 'finite'85 const hasPositionPhrase = ['second', 'third', 'fourth', 'fifth'].includes(targetNumber[0])86 const hasAreaPhrase = targetArea[0] === 'front' && (hasRangePhrase || targetCount[0] === 'all')87 const hasTargetType = !['unknown', 'magic', 'physics', 'summon', 'boss', 'nearWithoutOwner'].includes(targetType[0]) && targetCount[0] === 'all' ? false : true88 const hasDependAction = dependAction !== 0 && targetType[0] !== 'absolute' && [1, 3, 23, 28, 46].includes(Number(dependAction.action_type))89 const ignoresOne = !['unknown', 'random', 'randomOnce', 'absolute', 'summon', 'selfSummonRandom', 'allSummonRandom', 'magic', 'physics'].includes(targetType[0])90 const generatePhrase = () => {91 let targetPhraseTags = {92 custom: [],93 count: '',94 area: '',95 range: '',96 targetType: '',97 number: '',98 relation: ''99 }100 if (hasDependAction) {101 if ([1, 46].includes(Number(dependAction.action_type))) {102 targetPhraseTags.custom.push(`ã被ææ ${dependAction.action_id % 10} 伤害å°çã`)103 } else {104 targetPhraseTags.custom.push(`ãææ ${dependAction.action_id % 10} çç®æ ã`)105 }106 return targetPhraseTags107 }108 if (hasCountPhrase) {109 switch (targetCount) {110 case 'zero':111 break112 case 'one':113 if (!ignoresOne) targetPhraseTags.count = targetCount[1]114 break115 default:116 targetPhraseTags.count = targetCount[1]117 }118 }119 if (hasAreaPhrase) {120 if (targetArea[0] === 'front') {121 if (targetAssignment === 'ally') {122 targetPhraseTags.area = targetArea[1]123 } else {124 targetPhraseTags.custom.push('ãåæ¹ã')125 }126 }127 }128 if (targetRange === 'finite') {129 targetPhraseTags.range = `ãè·ç¦» ${action.target_range} ã`130 }131 if (hasTargetType) {132 targetPhraseTags.targetType = targetType[1]133 }134 if (hasPositionPhrase) {135 targetPhraseTags.number = targetNumber[1]136 }137 if (hasRelationPhrase) {138 targetPhraseTags.relation = targetAssignment[1]139 } else {140 targetPhraseTags = {141 custom: [],142 count: '',143 area: '',144 range: '',145 targetType: '',146 number: '',147 relation: ''148 }149 targetPhraseTags.targetType = targetType[1]150 }151 targetPhraseTags.custom.join('')152 return targetPhraseTags153 }154 const phrase = generatePhrase()155 phrase.targetType = phrase.targetType.replace(/\$1/, phrase.count)156 phrase.targetType = phrase.targetType.replace(/\$2/, phrase.number)157 const pattern = `${phrase.custom}${phrase.area}${phrase.range}${phrase.relation}${phrase.targetType}`158 return pattern159}160export default {161 getSkillActionDetails: ({ action, dependAction, unitAtk, unitMAtk, unitLevel, skillLevel }) => {162 let detail163 skillLevel = skillLevel || unitLevel164 switch (action.action_type) {165 case 1:166 detail = Actions.Type1.DealDamage(action, unitAtk, unitMAtk, unitLevel, skillLevel)167 break168 case 2:169 detail = Actions.Type2.Move(action)170 break171 case 3:172 detail = Actions.Type3.Knock(action)173 break174 case 4:175 detail = Actions.Type4.DealHeal(action, unitAtk, unitMAtk, unitLevel, skillLevel)176 break177 case 6:178 detail = Actions.Type6.SetBarrier(action, skillLevel)179 break180 case 7:181 detail = Actions.Type7.Reflexive(action)182 break183 case 8:184 detail = Actions.Type8.DealAilment(action, skillLevel)185 break186 case 9:187 detail = Actions.Type9.DealDamageOverTime(action, skillLevel)188 break189 case 10:190 detail = Actions.Type10.CastAura(action, skillLevel)191 break192 case 11:193 detail = Actions.Type11.CastCharm(action, skillLevel)194 break195 case 12:196 detail = Actions.Type12.CastDarkness(action, skillLevel)197 break198 case 13:199 detail = Actions.Type13.CastSilence(action, skillLevel)200 break201 case 14:202 detail = Actions.Type14.ChangeMode(action)203 break204 case 15:205 detail = Actions.Type15.Summon(action).detail206 break207 case 16:208 detail = Actions.Type16.ChangeEnergy(action, skillLevel)209 break210 case 17:211 detail = Actions.Type17.Trigger(action)212 break213 case 18:214 detail = Actions.Type18.ChargingDamage(action, skillLevel)215 break216 case 20:217 detail = Actions.Type20.SetDecoy(action, skillLevel)218 break219 case 21:220 detail = Actions.Type21.Invulnerable(action, skillLevel)221 break222 case 22:223 detail = Actions.Type22.ChangeAttackPattern(action)224 break225 case 23:226 detail = Actions.Type23.IfForChildren(action)227 break228 case 24:229 detail = Actions.Type24.CastResurrect(action)230 break231 case 26:232 detail = Actions.Type26.Additive(action, skillLevel)233 break234 case 27:235 detail = Actions.Type27.Multiple(action, skillLevel)236 break237 case 28:238 detail = Actions.Type28.IfForAll(action)239 break240 case 30:241 detail = Actions.Type30.CastInstantDeath()242 break243 case 32:244 detail = Actions.Type32.EnchantLifeSteal(action, skillLevel)245 break246 case 33:247 detail = Actions.Type33.SetCounterBackBarrier(action, skillLevel)248 break249 case 34: 250 detail = Actions.Type34.AccumulativeDamage(action, skillLevel)251 break252 case 35:253 detail = Actions.Type35.SetMark(action)254 break255 case 36:256 detail = Actions.Type36.DealFieldDamage(action, unitAtk, unitMAtk, unitLevel, skillLevel)257 break258 case 37:259 detail = Actions.Type37.DealFieldHeal(action, unitAtk, unitMAtk, unitLevel, skillLevel)260 break261 case 38:262 detail = Actions.Type38.CastFieldAura(action, skillLevel)263 break264 case 42:265 detail = Actions.Type42.LoopTrigger(action, skillLevel)266 break267 case 44:268 detail = Actions.Type44.Delayed(action)269 break270 case 45:271 detail = Actions.Type45.SkillCounter(action)272 break273 case 46:274 detail = Actions.Type46.DealRatioDamage(action, skillLevel)275 break276 case 47:277 detail = Actions.Type47.DealLimitedDamage(action, unitAtk, unitMAtk, unitLevel, skillLevel)278 break279 case 48:280 detail = Actions.Type48.DealRegeneration(action, unitAtk, unitMAtk, unitLevel, skillLevel)281 break282 case 49:283 detail = Actions.Type49.CastDispel(action, skillLevel)284 break285 case 50:286 detail = Actions.Type50.ChannelingAura(action, skillLevel)287 break288 case 52:289 detail = Actions.Type52.ChangeWidth(action)290 break291 case 53:292 detail = Actions.Type53.FieldCondition(action)293 break294 case 90:295 detail = Actions.Type90.PassiveSkill(action, skillLevel)296 break297 default:298 return299 }300 return {301 detail,302 target: targetAnalyzer(action, dependAction)303 }304 }...
relative.js
Source:relative.js
...41// å·¥å
·æ¹æ³ å¤æ对象类å42function getTargetType(value) {43 return !Object.isExtensible(value)44 ? TargetType.INVALID45 : targetTypeMap(toTypeString(value))46}47// å·¥å
·æ¹æ³ æ ¹æ®å¯¹è±¡ç±»åè¿åTargetTypeé
置类å48function targetTypeMap(rawType) {49 switch (rawType) {50 case 'Object':51 case 'Array':52 return TargetType.COMMON53 case 'Map':54 case 'Set':55 case 'WeakMap':56 case 'WeakSet':57 return TargetType.COLLECTION58 default:59 return TargetType.INVALID60 }61}62// å·¥å
·æ¹æ³ æ£æ¥å¯¹è±¡æ¯å¦æReactiveFlags.RAWå±æ§,åå¨å³è¿å该å±æ§ï¼å¦åè¿åå对象...
TMap.js
Source:TMap.js
1import Map from 'ol/Map.js'2import View from 'ol/View.js'3import { getTopLeft } from 'ol/extent.js'4import { get as getProjection } from 'ol/proj.js'5import LayerGroup from 'ol/layer/Group'6import WMTS from 'ol/source/WMTS.js'7import WMTSTileGrid from 'ol/tilegrid/WMTS.js'8import TileLayer from 'ol/layer/Tile.js'9import fetchJsonp from './fetchJsonp'10import _without from 'lodash/without'11import _debounce from 'lodash/debounce'12// import TileWMS from 'ol/source/TileWMS.js';13let projection = getProjection('EPSG:4326')14let maxLevel = 2015export class TMap extends Map {16 layerArray=[];//å°å¾å¾å±æ°ç»17 events={};//å°å¾äºä»¶å表18 constructor (id, center = [120.158, 30.267], level = 16, maptype = 'emap') {19 super({20 logo: false,21 target: id,22 // interactions: new ol.interaction.defaults({23 // pinchRotate: false24 // }),25 // controls: [26 // new ol.control.ScaleLine({ className: "scale-line", minWidth: "45" }),27 // new ol.control.Zoom({ className: "zoom-bar" })28 // ],29 // layers: [30 // new TileLayer({31 // source: new TileWMS({32 // url: 'https://ahocevar.com/geoserver/wms',33 // params: {34 // 'LAYERS': 'ne:NE1_HR_LC_SR_W_DR',35 // 'TILED': true36 // }37 // })38 // })39 // ],40 view: new View({41 center: center,42 projection: projection,43 zoom: level,44 maxZoom: maxLevel,45 minZoom: 246 }),47 moveTolerance: 1048 })49 this.maptype = maptype;50 this.level=level;51 this.center=center;52 this.setOnlineMapType(maptype, center, level)53 }54 getMapType() {55 return this.maptype;56 }57 setOnlineMapType (maptype, center, zoom) {58 //请æ±å¤©å°å¾å¾å±59 var view = this.getView();60 var bbox = view.calculateExtent().join(',');61 //fetchJsonp("http://121.43.99.232:8899/api/maplayer/current",{62 fetchJsonp('http://www.zjditu.cn/api/maplayer/current', {63 bbox: bbox, zoom: zoom64 }, { jsonpCallback:'_cb', timeout: 20000 }).then((response) => {65 if (response.code === 200) {66 this.addOnlineMap(maptype, center, zoom, response.content);67 }68 }).catch((error) => {69 if(error.message.indexOf('abort')>=0) {70 console.log(error.message);71 }else {72 console.log(error.message);73 //å¦æ请æ±è¶
æ¶ï¼éæ°è¯·æ±74 if(error.message.indexOf('time')>=0) {75 this.setOnlineMapType(maptype, center, zoom);76 }77 }78 });79 }80 //å è½½å¨çº¿å°å¾81 addOnlineMap(maptype, center, level, mapConfigArray) {82 //å¦æå½åçå°å¾ç±»åä¸æ¯ç®æ ç±»åï¼ååæ¢83 let currentMapType =this.getMapType();84 let targetTypeMap=null;//ç®æ å¾å±85 let currentTypeMap=null;//å½åå¾å±86 let mapColle = this.getLayers().getArray();87 for (let i = 0; i < mapColle.length; i++) {88 if (mapColle[i].get('name')===currentMapType) {89 currentTypeMap=mapColle[i];90 }91 if(mapColle[i].get('name')===maptype) {92 targetTypeMap=mapColle[i];93 }94 }95 if (currentMapType !== maptype) {96 currentTypeMap.setVisible(false);97 }else {98 targetTypeMap=currentTypeMap;99 }100 if (targetTypeMap) {101 targetTypeMap.setVisible(true);102 } else {103 targetTypeMap = new LayerGroup({104 name: maptype,105 isBaseLayers: true,106 layers: []107 })108 this.addLayer(targetTypeMap);109 }110 //å¤æåªäºå¾å±æ¯å½åå¾å±æ°ç»ä¸æ²¡æçï¼æ²¡æçå ä¸ï¼å¦æé
ç½®æ件ä¸æ²¡æï¼å¨å½åå¾å±æ°ç»ä¸åå¨ï¼åå é¤å¾å±ï¼ä¸åå è½½111 //å¦ææ§è¡è¯·æ±currentå½æ°åï¼å¾å±å称没æååï¼åä¸è¿è¡ä¸é¢çå è½½å¾å±ä»£ç æ§è¡112 let templayerNameArray=[];113 for(let mapConfig of mapConfigArray) {114 templayerNameArray.push(mapConfig.id);115 }116 let targetLayerColle=targetTypeMap.getLayers();117 let targetLayers=targetLayerColle.getArray();118 for(let i=0;i< targetLayers.length;i++) {119 let layer=targetLayers[i];120 let layerid=layer.get('id');121 if(templayerNameArray.indexOf(layerid)>=0) {122 continue;123 }else {124 targetLayerColle.remove(layer);125 i--;126 this.layerArray=_without(this.layerArray, layerid);127 }128 }129 //建ç«å¾å±130 var layerArray = [];131 var layerCount = mapConfigArray.length;132 for (let i = 0; i < layerCount; i++) {133 var mapConfig = mapConfigArray[i];134 //å¦æåå¨ååå¾å±ï¼ä¸åå è½½ï¼é¿å
äºå½æ°éå135 if (this.layerArray.indexOf(mapConfig.id)>=0) {136 continue;137 }138 var url=mapConfig.url139 if (url.indexOf('{s}') >= 0) {140 url=url.replace('{s}', '{0-6}');141 }142 //å¤æå è½½çå¾å±143 var tagsFlag = -1;144 switch (maptype) {145 case 'img':146 tagsFlag = mapConfig.tags.search(/img(?!.)|(?:img,label)/);147 break;148 case 'img_2000':149 tagsFlag = mapConfig.tags.search(/img_2000/);150 break;151 case 'img_70':152 tagsFlag = mapConfig.tags.search(/img_70/);153 break;154 case 'img_60':155 tagsFlag = mapConfig.tags.search(/img_60/);156 break;157 default:158 tagsFlag = mapConfig.tags.search(/road(?!.)|(?:road,label)/);159 break;160 }161 if (tagsFlag >= 0) {162 //var minR = mapConfig.max; //æå°å辨ç163 //var maxR = mapConfig.min-1; //æ大å辨ç164 let source= new WMTS({165 url: url,166 id:mapConfig.id,167 style: mapConfig.style,168 format: mapConfig.format,169 layer: mapConfig.layer,170 matrixSet: mapConfig.wmts_tile_matrixset,171 projection:projection,172 tileGrid: new WMTSTileGrid({173 origin: this.origin,174 resolutions: this.resolutions,175 matrixIds: this.matrixIds176 })177 });178 source.on('tileloaderror', function(event) {179 console.log(event)180 //let tile=event.tile181 //let img=tile.getImage();182 //img.src=require('../assets/images/zjbg.png');183 });184 var newlayer = new TileLayer({185 name: mapConfig.name,186 id:mapConfig.id,187 group: maptype,188 isBaseLayers: mapConfig.baselayer,189 source:source,190 //minResolution: this.resolutions[minR],191 //maxResolution: this.resolutions[maxR],192 zIndex: mapConfig.zindex ? mapConfig.zindex : 0193 });194 layerArray.push(newlayer);195 //åå¨å¾å±å称196 this.layerArray.push(mapConfig.id);197 }198 }199 //å å
¥å¾å±ç»200 targetTypeMap.getLayers().extend(layerArray);201 this.maptype = maptype;202 if (!this.events['moveend']) {203 this.events['moveend'] = this.on('moveend', _debounce((event) => {204 let view=this.getView();205 this.setOnlineMapType(this.getMapType(), view.getCenter(), view.getZoom());206 }, 500));207 }208 return targetTypeMap;209 }210}211Object.assign(TMap.prototype, {212 maxLevel: 20,213 projection: projection,214 origin: (function () {215 let projection = getProjection('EPSG:4326')216 let projectionExtent = projection.getExtent()217 return getTopLeft(projectionExtent)218 })(),219 resolutions: [1.40625, 0.703125, 0.3515625, 0.17578125, 0.087890625, 0.0439453125, 0.02197265625, 0.010986328125,220 0.0054931640625, 0.00274658203125, 0.001373291015625, 0.0006866455078125, 0.00034332275390625, 0.000171661376953125,221 0.0000858306884765625, 0.00004291534423828125, 0.000021457672119140625, 0.000010728836059570312, 0.000005364418029785156,222 0.000002682209014892578, 0.000001341104507446289],223 matrixIds: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]...
tree-modal-category.js
Source:tree-modal-category.js
1import intl from 'react-intl-universal'2import {Component} from 'react'3import {action} from 'mobx'4import {observer} from 'mobx-react'5import {Modal, Button} from 'antd'6import {Time, debounce} from '../../common/util'7import {ModalForm, ModalDetail} from '../../component'8import {targetTypeMap, nameTypeMap, modalDefaultConfig} from './util'9@observer10class ModalCategory extends Component {11 constructor(props) {12 super(props)13 this.store = props.store14 }15 renderContent() {16 const {17 categoryModal: {editType},18 } = this.store19 // æ¥ç详æ
20 if (editType === 'view') {21 return this.renderDetail()22 }23 // ç¼è¾/æ·»å 24 return this.renderEditModal()25 }26 /*27 * @description 渲æç¼è¾å¼¹çª28 */29 renderEditModal() {30 const {31 categoryModal: {detail, editType, visible},32 confirmLoading,33 } = this.store34 const content = [35 {36 label: intl37 .get(38 'ide.src.page-manage.page-object-model.object-list.object-list.modal-category.aps4bfdj6ls'39 )40 .d('ç±»ç®å称'),41 key: 'name',42 initialValue: detail.name,43 component: 'input',44 rules: [45 '@namePattern',46 '@nameUnderline',47 '@nameShuQi',48 '@transformTrim',49 '@required',50 '@max32',51 {validator: this.checkName},52 ],53 },54 {55 label: intl56 .get('ide.src.component.modal-stroage-detail.main.lyqo7nv5t9h')57 .d('æè¿°'),58 key: 'descr',59 initialValue: detail.descr,60 component: 'textArea',61 rules: ['@max128'],62 },63 ]64 const modalConfig = {65 title:66 editType === 'edit'67 ? intl68 .get(69 'ide.src.page-manage.page-object-model.tree-modal-category.ccndgjgllw'70 )71 .d('ç¼è¾å¯¹è±¡ç±»ç®')72 : intl73 .get(74 'ide.src.page-manage.page-object-model.tree-action.znat69vvyk8'75 )76 .d('æ°å»ºå¯¹è±¡ç±»ç®'),77 visible,78 onCancel: this.handleCancel,79 onOk: this.submit,80 confirmLoading,81 ...modalDefaultConfig,82 }83 const formConfig = {84 selectContent: visible && content,85 wrappedComponentRef: form => {86 this.form = form ? form.props.form : form87 },88 }89 return (90 <Modal {...modalConfig}>91 <ModalForm {...formConfig} />92 </Modal>93 )94 }95 /*96 * @description 渲æ详æ
å¼¹çª97 */98 renderDetail() {99 const {categoryModal} = this.store100 const {detail} = categoryModal101 const modalConfig = {102 title: intl103 .get(104 'ide.src.page-manage.page-object-model.tree-modal-category.gyvotw5kfow'105 )106 .d('对象类ç®è¯¦æ
'),107 visible: categoryModal.visible,108 onCancel: this.handleCancel,109 onOk: this.submit,110 footer: [111 <Button onClick={this.handleCancel}>112 {intl113 .get('ide.src.component.modal-stroage-detail.main.ph80bkiru5h')114 .d('å
³é')}115 </Button>,116 ],117 ...modalDefaultConfig,118 }119 const content = [120 {121 name: intl122 .get(123 'ide.src.page-manage.page-object-model.object-list.object-list.modal-category.aps4bfdj6ls'124 )125 .d('ç±»ç®å称'),126 value: detail.name,127 },128 {129 name: intl130 .get('ide.src.page-manage.page-common-tag.detail.main.hv8quje3qk')131 .d('å建è
'),132 value: detail.creator,133 },134 {135 name: intl136 .get(137 'ide.src.page-manage.page-aim-source.source-detail.main.2vp94m4091h'138 )139 .d('å建æ¶é´'),140 value: <Time timestamp={detail.createTime} />,141 },142 {143 name: intl144 .get('ide.src.component.modal-stroage-detail.main.lyqo7nv5t9h')145 .d('æè¿°'),146 value: detail.descr,147 },148 ]149 return (150 <Modal {...modalConfig}>151 <ModalDetail data={content} labelWidth={52} />152 </Modal>153 )154 }155 @action checkName = (rule, value, callback) => {156 const {157 categoryModal: {detail},158 } = this.store159 const params = {160 name: value,161 type: targetTypeMap.category, // ç±»å:0 ç±»ç® 1 对象162 nameType: nameTypeMap[rule.field], // å称类å: 1 ä¸æå 2 è±æå163 }164 // ç¼è¾ç¶æ165 if (detail.aId) {166 params.id = detail.aId167 }168 debounce(() => this.store.checkName(params, callback), 500)169 // this.store.checkName(params, callback)170 }171 @action.bound handleCancel() {172 this.store.categoryModal.visible = false173 this.store.confirmLoading = false174 }175 submit = () => {176 const t = this177 const {store} = t178 const {179 categoryModal: {editType, detail, type},180 } = store181 this.form.validateFields((err, values) => {182 if (!err) {183 // ç¼è¾184 if (editType === 'edit') {185 const params = {id: detail.id, ...values}186 store.editNode(params, type, () => {187 t.handleCancel()188 })189 } else {190 // æ°å¢191 store.addNode(values, type, () => {192 t.handleCancel()193 })194 }195 }196 })197 }198 render() {199 return this.renderContent()200 }201}...
reactive.js
Source:reactive.js
...10const reactiveMap = new WeakMap()11const readonlyMap = new WeakMap()12const shallowReadonlyMap = new WeakMap()13const shallowReactiveMap = new WeakMap()14function targetTypeMap(rawType) {15 switch (rawType) {16 case 'Object':17 case 'Array':18 return TargetType.COMMON19 case 'Map':20 case 'Set':21 case 'WeakMap':22 default:23 return TargetType.INVALID24 }25}26function getTargetType(value) {27 return value[SKIP] || !Object.isExtensible(value)28 ? TargetType.INVALID29 : targetTypeMap(toRawType(value))30}31function createGetter(isReadOnly = false, shallow = false) {32 return function get(target, key, receiver) {33 // å¤ææ¯å¦ä¸ºreactive34 if(key === IS_REACTIVE) return !isReadOnly35 // å¤ææ¯å¦ä¸ºreadonly36 else if(key === IS_READONLY) return isReadOnly37 // toRawæä½å¤æ38 else if(39 key === RAW &&40 receiver === 41 (42 isReadOnly43 ? shallow...
k8s-manifest.mjs
Source:k8s-manifest.mjs
1import k8s from "@kubernetes/client-node";2import yaml from "yaml";3class K8sManifest {4 constructor(parsedYaml) {5 if (!parsedYaml || !parsedYaml.kind)6 throw new Error(`The parsed yaml couldn't be used to construct a k8s object.\n${yaml.stringify(parsedYaml)}`);7 this._yaml = parsedYaml;8 const objectPrefix = this._objectVersion(this._yaml.apiVersion);9 this._obj = this._k8sClientObject(`${objectPrefix}${this._yaml.kind}`, this._yaml);10 }11 get kind() {12 return this._obj.kind;13 }14 get metadata() {15 return this._obj.metadata;16 }17 toString() {18 return k8s.dumpYaml(this._obj);19 }20 k8sClientObject() {21 return this._obj;22 }23 _k8sClientObject(typeName, value) {24 if (this._baseType(typeName, value)) {25 if (this._dateType(typeName) && !!value) {26 return new Date(value);27 }28 return value;29 } else if (this._arrayType(typeName)) {30 return this._handleArrayType(typeName, value);31 } else if (this._mapType(typeName)) {32 return this._handleMap(typeName, value);33 } else {34 return this._handleClientObjectType(typeName, value);35 }36 }37 _baseType(typeName, value) {38 return (!this._mapType(typeName) && !this._arrayType(typeName) && !this._object(value)) || this._dateType(typeName);39 }40 _object(value) {41 return typeof value === 'object';42 }43 _dateType(typeName) {44 return typeName === 'Date';45 }46 _arrayType(typeName) {47 return typeName.includes('Array');48 }49 _mapType(typeName) {50 return typeName.includes('{');51 }52 _attributeTypeMap(typeName, attributeName) {53 const attributeTypeMaps = k8s[typeName]['getAttributeTypeMap']();54 let targetTypeMap = {};55 for (const prospectiveTypeMap of attributeTypeMaps) {56 if (prospectiveTypeMap.name === attributeName) {57 targetTypeMap = prospectiveTypeMap;58 }59 }60 if (this._emptyMap(targetTypeMap)) {61 throw new Error(`62 The attribute with name ${attributeName} and type ${typeName} wasn't found in the type map. Are you sure it's acceptible in kubernetes yaml configurations?63 `);64 }65 return targetTypeMap;66 }67 _handleArrayType(typeName, value) {68 let subject = [];69 const elementType = typeName.match(/(?<=Array\<)(.*?)(?=\>)/)[0];70 if (!elementType) {71 throw new Error(`Could not match array element type for type ${typeName}`);72 }73 for (const entry of value) {74 subject.push(this._k8sClientObject(elementType, entry));75 }76 return subject;77 }78 _handleMap(typeName, value) {79 let subject = {};80 const propertyType = typeName.match(/(?<=\{ \[key: \w+\]: )(.*?)(?=; \})/)[0];81 for (const attribute in value) {82 subject[attribute] = this._k8sClientObject(propertyType, value[attribute]);83 }84 return subject;85 }86 _handleClientObjectType(typeName, value) {87 let subject = new k8s[typeName]();88 for (const attribute in value) {89 const targetTypeMap = this._attributeTypeMap(typeName, attribute);90 subject[attribute] = this._k8sClientObject(targetTypeMap.type, value[attribute]);91 }92 return subject;93 }94 _objectVersion(apiVersion) {95 if (!apiVersion.includes('/')) {96 return this._capitalizeFirstLetter(apiVersion);97 } else {98 const parts = apiVersion.split('/');99 const lastPart = parts[parts.length - 1];100 return this._capitalizeFirstLetter(lastPart);101 }102 }103 _capitalizeFirstLetter(string) {104 return string.charAt(0).toUpperCase() + string.slice(1);105 }106 _emptyMap(map) {107 return Object.keys(map).length === 0;108 }109}...
util.js
Source:util.js
1import treeUnfold from '../../icon/tree-unfold.svg'2import treeFold from '../../icon/tree-fold.svg'3export const deleteTipsMap = {4 category: {5 title: 'å é¤å¯¹è±¡ç±»ç®',6 content: '对象类ç®è¢«å é¤åä¸å¯æ¢å¤ï¼ç¡®å®å é¤ï¼',7 },8 obj: {9 title: 'å é¤å¯¹è±¡',10 content: '对象被å é¤åä¸å¯æ¢å¤ï¼ç¡®å®å é¤ï¼',11 },12}13// ç±»åæ å°:0 ç±»ç® 1 对象14export const targetTypeMap = {15 obj: 1,16 category: 0,17}18// å称类åæ å°: 1 ä¸æå 2 è±æå19export const nameTypeMap = {20 name: 1,21 enName: 2,22 objPk: 3,23}24export const TARGET_CATEGORY = 'category' // 对象类ç®25export const TARGET_OBJECT = 'obj' // 对象26export const REL_CODE = '3'27export const ENTITY_CODE = '4'28// å¼¹çªé»è®¤é
ç½®29export const modalDefaultConfig = {30 width: 525,31 maskClosable: false,32 destroyOnClose: true,33}34export const getIconNodeSrc = e => (e ? treeUnfold : treeFold)35// 对象类ç®å¸¦æ对象æ°éæ示36export const TreeNodeTitle = ({node}) => (37 <span>38 {39 node.parentId ? node.name : `${node.name} (${node.count || 0})`40 }41 </span>42)43export const judgeEditType = (data, editType) => (editType === 'edit' ? data : undefined)44//* --------------- 对象详æ
---------------*//45// æ ¹æ® å®ä½/对象 ç±»åcode() æ å°å¯¹åºæå46export const typeCodeMap = {47 4: 'å®ä½',48 3: 'å
³ç³»',49 '4ï½': 'å
³ç³»',50 '3ï½': 'å®ä½',51}52// 对象åå¸ç¶æå¼æ å°53export const objStatusMap = {54 release: 1,55 cancel: 0,56}57// 对象类åæ å°58export const objTypeMap = {59 0: 'ç®åå
³ç³»',60 1: 'å¤æå
³ç³»',61 2: 'å®ä½',62}63export const objTypeList = [{64 name: 'ç®åå
³ç³»',65 value: 0,66}, {67 name: 'å¤æå
³ç³»',68 value: 1,69}, {70 name: 'å®ä½',71 value: 2,...
ENUM.js
Source:ENUM.js
1window.ENUM = {2 sysUserStatus: {3 freeze: 'å»ç»',4 normal: 'æ£å¸¸',5 cancel: '注é'6 },7 checkStatus: {8 saved: 'åç',9 wait_audit: 'å¾
å®¡æ ¸',10 audited: 'å®¡æ ¸éè¿',11 unaudited: 'å®¡æ ¸ä¸éè¿'12 },13 checkStatusMap: [14 {value: 'saved', label: 'åç'},15 {value: 'wait_audit', label: 'å¾
å®¡æ ¸'},16 {value: 'audited', label: 'å®¡æ ¸éè¿'},17 {value: 'unaudited', label: 'å®¡æ ¸ä¸éè¿'},18 ],19 obCheckStatus: {20 saved: 'åç',21 wait_audit: 'å¾
å®¡æ ¸',22 audited: 'å®¡æ ¸éè¿',23 unaudited: 'å®¡æ ¸ä¸éè¿',24 discard: 'åºå¼'25 },26 obStatusTypeMap: [27 {value: 'saved', label: 'åç'},28 {value: 'wait_audit', label: 'å¾
å®¡æ ¸'},29 {value: 'audited', label: 'å®¡æ ¸éè¿'},30 {value: 'unaudited', label: 'å®¡æ ¸ä¸éè¿'},31 {value: 'discard', label: 'åºå¼'}32 ],33 platformObStatusTypeMap: [34 {value: 'wait_audit', label: 'å¾
å®¡æ ¸'},35 {value: 'audited', label: 'å®¡æ ¸éè¿'},36 {value: 'unaudited', label: 'å®¡æ ¸ä¸éè¿'},37 {value: 'discard', label: 'åºå¼'}38 ],39 targetType: {40 'platform': 'å¹³å°',41 'merchant': 'åæ·',42 'member': 'ä¼å',43 },44 targetTypeMap: [{45 value: 'platform',46 label: 'å¹³å°'47 }, {48 value: 'merchant',49 label: 'åæ·'50 }, {51 value: 'member',52 label: 'ä¼å'53 }],54 sex: {55 'female': '女',56 'male': 'ç·'57 },58 borrowerType: {59 'personal': '个人',60 'enterprise': 'ä¼ä¸'61 }...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const targetTypeMap = await page.evaluate(() => window._targetTypeMap);7 console.log(targetTypeMap);8 await browser.close();9})();10{11}12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 console.log(page.target().targetType());18 await browser.close();19})();20const { chromium } = require('playwright');21(async () => {22 const browser = await chromium.launch();23 const context = await browser.newContext();24 const page = await context.newPage();25 console.log(page.mainFrame().target().targetType());26 await browser.close();27})();28const { chromium } = require('playwright');29(async () => {30 const browser = await chromium.launch();31 const context = await browser.newContext();32 const page = await context.newPage();33 const worker = await page.evaluateHandle(() => new Worker(URL.createObjectURL(new Blob(['console.log("hi")'], { type: 'application/javascript' }))));34 console.log(worker.asElement().contentFrame().target().targetType());35 await browser.close();36})();37const { chromium } = require('
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const targetTypeMap = page._delegate.targetTypeMap();7 console.log(targetTypeMap);8 await browser.close();9})();10{11}12Example 2: Using targetTypeMap() method to get the target type of the current page13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 const targetTypeMap = page._delegate.targetTypeMap();19 const currentTargetType = targetTypeMap[page._delegate._targetInfo.type];20 console.log(currentTargetType);21 await browser.close();22})();23Example 3: Using targetTypeMap() method to get the target type of the current page in the browser context24const { chromium } = require('playwright');25(async () => {26 const browser = await chromium.launch();27 const context = await browser.newContext();28 const page = await context.newPage();29 const targetTypeMap = page._delegate.targetTypeMap();30 const currentTargetType = targetTypeMap[page._delegate._targetInfo.type];31 console.log(currentTargetType);32 await browser.close();33})();34Example 4: Using targetTypeMap() method to get the target type of the current page in the browser context35const { chromium } = require('playwright');36(async () => {37 const browser = await chromium.launch();38 const context = await browser.newContext();39 const page = await context.newPage();40 const targetTypeMap = page._delegate.targetTypeMap();41 const currentTargetType = targetTypeMap[page._delegate._targetInfo.type];42 console.log(currentTargetType);43 await browser.close();44})();
Using AI Code Generation
1const { chromium } = require('playwright');2const { targetTypeMap } = require('playwright/lib/server/chromium/crBrowser');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.fill('input[type="text"]', 'Playwright');8 await page.press('input[type="text"]', 'Enter');9 const target = await page.waitForTarget(t => t.url().includes('playwright.dev'));10 console.log(targetTypeMap[target.type()]);11 await target.page();12 await browser.close();13})();
Using AI Code Generation
1const path = require('path');2const playwright = require('playwright');3const { targetTypeMap } = require(path.join(4 path.dirname(require.resolve('playwright')),5));6(async () => {7 const browser = await playwright.chromium.launch();8 const page = await browser.newPage();9 console.log(targetTypeMap);10 await browser.close();11})();12{13}14const path = require('path');15const playwright = require('playwright');16const { targetTypeMap } = require(path.join(17 path.dirname(require.resolve('playwright')),18));19console.log(targetTypeMap);20{21}
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 console.log(page.targetTypeMap());6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch();11 const page = await browser.newPage();12 console.log(page.targetTypeMap());13 await browser.close();14})();15const { chromium } = require('playwright');16(async () => {17 const browser = await chromium.launch();18 const page = await browser.newPage();19 console.log(page.targetTypeMap());20 await browser.close();21})();22const { chromium } = require('playwright');23(async () => {24 const browser = await chromium.launch();25 const page = await browser.newPage();26 console.log(page.targetTypeMap());27 await browser.close();28})();29const { chromium } = require('playwright');30(async () => {31 const browser = await chromium.launch();32 const page = await browser.newPage();33 console.log(page.targetTypeMap());34 await browser.close();35})();
Using AI Code Generation
1const { chromium, webkit, firefox } = require('playwright');2const { targetTypeMap } = require('playwright/lib/server/chromium/crBrowser');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 console.log(targetTypeMap);7 await browser.close();8})();9{10}11const { chromium, webkit, firefox } = require('playwright');12const { targetTypeMap } = require('playwright/lib/server/chromium/crBrowser');13(async () => {14 const browser = await chromium.launch();15 const page = await browser.newPage();16 const pageTarget = browser.targets().find(target => target.type() === targetTypeMap.page);17 console.log(pageTarget);18 await browser.close();19})();20Target {21 _browserContext: BrowserContext {22 _pageBindings: Map(0) {},23 _ownedPages: Set(1) [ [Page] ],
Using AI Code Generation
1const { chromium } = require('playwright');2const { targetTypeMap } = require('playwright/lib/server/chromium/crBrowser');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const target = await page.target();8 const type = targetTypeMap.get(target._targetInfo.type);9 console.log(type);10 await browser.close();11})();
Using AI Code Generation
1const { Internal } = require('playwright');2const { targetTypeMap } = new Internal();3const { Internal } = require('playwright');4const { targetTypeMap } = new Internal();5const { Internal } = require('playwright');6const { targetTypeMap } = new Internal();7const { Internal } = require('playwright');8const { targetTypeMap } = new Internal();9const { Internal } = require('playwright');10const { targetTypeMap } = new Internal();11const { Internal } = require('playwright');12const { targetTypeMap } = new Internal();13const { Internal } = require('playwright');14const { targetTypeMap } = new Internal();15const { Internal } = require('playwright');16const { targetTypeMap } = new Internal();17const { Internal } = require('playwright');18const { targetTypeMap } = new Internal();19const { Internal } = require('playwright');20const { targetTypeMap } = new Internal();21const { Internal } = require('playwright');22const { targetTypeMap } = new Internal();23const { Internal } = require('playwright');24const { targetTypeMap } = new Internal();25const { Internal } = require('playwright');26const { targetTypeMap } = new Internal();27const { Internal } = require('playwright');28const { targetTypeMap } = new Internal();29const { Internal } = require('
Using AI Code Generation
1const path = require('path');2const playwright = require('playwright');3const { chromium } = require('playwright');4const { targetTypeMap } = require(path.join(5 path.dirname(require.resolve('playwright')),6));7(async () => {8 const browser = await chromium.launch();9 const page = await browser.newPage();10 const target = await page.target();11 const targetType = targetTypeMap.get(target._targetInfo.type);12 console.log(targetType);13 await browser.close();14})();
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!