Best JavaScript code snippet using ng-mocks
DATABIND_COMPONENTS.js
Source:DATABIND_COMPONENTS.js
1/**2 * æ°æ®ç»å®é
置页é¢æ¯æçç»ä»¶å表åé
置信æ¯3 * components[n] æ°æ®ç»å®é
置页é¢åç»ä»¶ï¼å
¶å
·ä½é
ç½®å±æ§å¦ä¸ï¼4 * type {String} ç»ä»¶ç±»å5 * show {Boolean} ç»ä»¶å¾æ æ¯å¦å±ç¤º é»è®¤true6 * switch {Boolean} æ¯å¦å¯ä»¥åæ¢è³å
¶ä»ç»ä»¶ é»è®¤true7 * iconClass {String} ç»ä»¶å¾æ 对åºç±»å8 * cells {Array} ç»ä»¶æ¯æçå段æ¡éå9 * cells[n] {Object} å个å段æ¡é
置对象10 * cells[n].collectType: 0 ä¸å¯æ±æ» 1 å¿
é¡»æ±æ» 2 å¯æ±æ»11 * cells[n].min æ ¼åæå°å段æ°é12 * cells[n].max æ ¼åæå¤å段æ°é13 * cells[n].valid(len,lenArr) æ ¼åå
å段æ
åµéªè¯ len{Number}: å½åæ ¼åå
å«çå段æ°é lenArr{Aray}: å½åæ ¼åç»çå段æ°éå14 * allowFieldTypes {Array} æ ¼åå¯æ¥æ¶å段çç±»åéåï¼å¦æä¸è®¾ç½®è¯¥å段åè¡¨ç¤ºè¯¥æ ¼åä¸éå¶æå
¥å段çç±»å15 */16/**17 *18 * @param {Number} len å½åæ ¼åå
å«çå段æ°é19 * @param {Array} lenArr å½åæ ¼åç»çå段æ°éå20 */21function commonValid(len, lenArr) {22 let result = {23 accept: true,24 result: true,25 errmsg: ""26 };27 let { min, max } = this;28 if (min && len < min) {29 result.result = false;30 result.errmsg = this.tip ? this.tip : "è³å°éè¦" + min + "个å段";31 }32 if (max && len > max) {33 result.result = false;34 result.errmsg = "å段æ°éè¶
åºï¼æå¤å
许" + max + "个å段";35 }36 if (max && len >= max) {37 result.accept = false;38 }39 return result;40}41export default [42 {43 type: "table",44 name: "è¡¨æ ¼",45 iconClass: "layout-table",46 cells: [47 {48 title: "表å",49 valueKey: "datas",50 collectType: {51 defaultValue: 0,52 selectValue: 253 },54 valid: commonValid55 }56 ]57 },58 {59 type: "chartBar",60 name: "æ±ç¶å¾",61 iconClass: "layout-bar",62 cells: [63 {64 title: "xè½´",65 valueKey: "xAxis",66 min: 1,67 max: 4,68 dirll: true,69 collectType: {70 defaultValue: 0,71 selectValue: 072 },73 valid: commonValid74 },75 {76 title: "ç³»å",77 valueKey: "series",78 max: 1,79 collectType: {80 defaultValue: 0,81 selectValue: 082 },83 valid: commonValid84 },85 {86 title: "yè½´",87 valueKey: "yAxis",88 min: 1,89 max: 5,90 collectType: {91 defaultValue: 1,92 selectValue: 193 },94 valid: commonValid95 }96 ]97 },98 {99 type: "chartPie",100 name: "饼å¾",101 iconClass: "layout-pie",102 cells: [103 {104 title: "ç±»å«",105 valueKey: "types",106 min: 1,107 max: 4,108 dirll: true,109 collectType: {110 defaultValue: 0,111 selectValue: 0112 },113 valid: commonValid114 },115 {116 title: "ææ ",117 valueKey: "counter",118 min: 1,119 max: 1,120 collectType: {121 defaultValue: 1,122 selectValue: 1123 },124 valid: commonValid125 }126 ]127 },128 {129 type: "chartLine",130 name: "æ线å¾",131 iconClass: "layout-line",132 cells: [133 {134 title: "xè½´",135 valueKey: "xAxis",136 min: 1,137 max: 4,138 dirll: true,139 collectType: {140 defaultValue: 0,141 selectValue: 0142 },143 valid: commonValid144 },145 {146 title: "ç³»å",147 valueKey: "series",148 max: 1,149 collectType: {150 defaultValue: 0,151 selectValue: 0152 },153 valid: commonValid154 },155 {156 title: "yè½´",157 valueKey: "yAxis",158 min: 1,159 max: 5,160 collectType: {161 defaultValue: 1,162 selectValue: 1163 },164 valid: commonValid165 }166 ]167 },168 {169 type: "chartMix",170 name: "ææ±æ··åå¾",171 iconClass: "layout-linebar",172 cells: [173 {174 title: "xè½´",175 valueKey: "xAxis",176 min: 1,177 max: 4,178 dirll: true,179 collectType: {180 defaultValue: 0,181 selectValue: 0182 },183 valid: commonValid184 },185 {186 title: "ç³»å",187 valueKey: "series",188 max: 1,189 collectType: {190 defaultValue: 0,191 selectValue: 0192 },193 valid: commonValid194 },195 {196 title: "æ±ç¶ææ ",197 valueKey: "barCount",198 max: 5,199 collectType: {200 defaultValue: 1,201 selectValue: 1202 },203 valid: function(len, arr) {204 let result = commonValid.call(this, len, arr);205 if (arr[2] === 0 && arr[3] === 0) {206 result.result = false;207 result.errmsg = "æ±ç¶ææ åæ线ææ è³å°å
¶ä¸ä¸ä¸ªæå段";208 }209 return result;210 }211 },212 {213 title: "æ线ææ ",214 valueKey: "lineCount",215 max: 5,216 collectType: {217 defaultValue: 1,218 selectValue: 1219 },220 valid: function(len, arr) {221 let result = commonValid.call(this, len, arr);222 if (arr[2] === 0 && arr[3] === 0) {223 result.result = false;224 result.errmsg = "æ±ç¶ææ åæ线ææ è³å°å
¶ä¸ä¸ä¸ªæå段";225 }226 return result;227 }228 }229 ]230 },231 {232 type: "chartDot",233 name: "大æ°æ®æ£ç¹å¾",234 iconClass: "layout-dot",235 cells: [236 {237 title: "å称",238 valueKey: "name",239 min: 1,240 max: 1,241 collectType: {242 defaultValue: 0,243 selectValue: 0244 },245 valid: commonValid246 },247 {248 title: "ç±»å«",249 valueKey: "types",250 max: 1,251 collectType: {252 defaultValue: 0,253 selectValue: 0254 },255 valid: commonValid256 },257 {258 title: "xè½´",259 valueKey: "xAxis",260 allowFieldTypes: ["number"],261 min: 1,262 max: 1,263 tip: "éæå
¥1个æ°å¼å段",264 collectType: {265 defaultValue: 0,266 selectValue: 2267 },268 valid: commonValid269 },270 {271 title: "yè½´",272 valueKey: "yAxis",273 allowFieldTypes: ["number"],274 min: 1,275 max: 1,276 tip: "éæå
¥1个æ°å¼å段",277 collectType: {278 defaultValue: 0,279 selectValue: 2280 },281 valid: commonValid282 },283 {284 title: "大å°",285 valueKey: "size",286 allowFieldTypes: ["number"],287 max: 1,288 collectType: {289 defaultValue: 0,290 selectValue: 2291 },292 valid: commonValid293 }294 ]295 },296 {297 type: "chartNestpie",298 name: "åµå¥ç¯å½¢å¾",299 iconClass: "layout-nestpie",300 cells: [301 {302 title: "ç±»å«1",303 valueKey: "series1",304 max: 1,305 collectType: {306 defaultValue: 0,307 selectValue: 0308 },309 valid: function(len, arr) {310 let result = commonValid.call(this, len, arr);311 if (arr[0] === 0 && arr[1] === 0 && arr[2] === 0) {312 result.result = false;313 result.errmsg = "ç±»å«1ãç±»å«2ãç±»å«3è³å°å
¶ä¸ä¸ä¸ªæå段";314 }315 return result;316 }317 },318 {319 title: "ç±»å«2",320 valueKey: "series2",321 max: 1,322 collectType: {323 defaultValue: 0,324 selectValue: 0325 },326 valid: function(len, arr) {327 let result = commonValid.call(this, len, arr);328 if (arr[0] === 0 && arr[1] === 0 && arr[2] === 0) {329 result.result = false;330 result.errmsg = "ç±»å«1ãç±»å«2ãç±»å«3è³å°å
¶ä¸ä¸ä¸ªæå段";331 }332 return result;333 }334 },335 {336 title: "ç±»å«3",337 valueKey: "series3",338 max: 1,339 collectType: {340 defaultValue: 0,341 selectValue: 0342 },343 valid: function(len, arr) {344 let result = commonValid.call(this, len, arr);345 if (arr[0] === 0 && arr[1] === 0 && arr[2] === 0) {346 result.result = false;347 result.errmsg = "ç±»å«1ãç±»å«2ãç±»å«3è³å°å
¶ä¸ä¸ä¸ªæå段";348 }349 return result;350 }351 },352 {353 title: "ææ ",354 valueKey: "counter",355 min: 1,356 max: 1,357 collectType: {358 defaultValue: 1,359 selectValue: 1360 },361 valid: commonValid362 }363 ]364 },365 {366 type: "chartRose",367 name: "åä¸æ ¼å°ç«ç°å¾",368 iconClass: "layout-rose",369 cells: [370 {371 title: "ç±»å«",372 valueKey: "types",373 min: 1,374 max: 4,375 dirll: true,376 collectType: {377 defaultValue: 0,378 selectValue: 0379 },380 valid: commonValid381 },382 {383 title: "ææ ",384 valueKey: "counter",385 min: 1,386 max: 1,387 collectType: {388 defaultValue: 1,389 selectValue: 1390 },391 valid: commonValid392 }393 ]394 },395 {396 type: "heatchart",397 iconClass: "layout-heatchart",398 name: "çåå¾",399 cells: [400 {401 title: "xè½´",402 valueKey: "xAxis",403 min: 1,404 max: 1,405 collectType: {406 defaultValue: 0,407 selectValue: 0408 },409 valid: commonValid410 },411 {412 title: "yè½´",413 valueKey: "yAxis",414 min: 1,415 max: 1,416 collectType: {417 defaultValue: 0,418 selectValue: 0419 },420 valid: commonValid421 },422 {423 title: "ææ ",424 valueKey: "counter",425 min: 1,426 max: 1,427 collectType: {428 defaultValue: 1,429 selectValue: 1430 },431 valid: commonValid432 }433 ]434 },435 {436 type: "chartFunnel",437 iconClass: "layout-chartFunnel",438 name: "æ¼æå¾",439 cells: [440 {441 title: "ç±»å«",442 valueKey: "types",443 min: 1,444 max: 4,445 dirll: true,446 collectType: {447 defaultValue: 0,448 selectValue: 0449 },450 valid: commonValid451 },452 {453 title: "ææ ",454 valueKey: "counter",455 min: 1,456 max: 1,457 collectType: {458 defaultValue: 1,459 selectValue: 1460 },461 valid: commonValid462 }463 ]464 },465 {466 type: "chartGauge",467 iconClass: "layout-chartgauge",468 name: "æ²¹éå¾",469 cells: [470 {471 title: "ææ ",472 valueKey: "counter",473 min: 1,474 max: 1,475 collectType: {476 defaultValue: 1,477 selectValue: 1478 },479 valid: commonValid480 }481 ]482 },483 {484 type: "chartWordCloud",485 iconClass: "layout-wordCloud",486 name: "è¯äºå¾",487 cells: [488 {489 title: "è¯å",490 valueKey: "types",491 min: 1,492 max: 1,493 collectType: {494 defaultValue: 0,495 selectValue: 0496 },497 valid: commonValid498 },499 {500 title: "ææ ",501 valueKey: "counter",502 max: 1,503 collectType: {504 defaultValue: 1,505 selectValue: 1506 },507 valid: commonValid508 }509 ]510 },511 {512 type: "graph",513 name: "å
³èå
³ç³»å¾",514 iconClass: "layout-graph",515 cells: [516 {517 title: "æºèç¹",518 valueKey: "node",519 min: 1,520 max: 1,521 collectType: {522 defaultValue: 0,523 selectValue: 0524 },525 valid: commonValid526 },527 {528 title: "æºèç¹ç±»å«",529 valueKey: "nodeType",530 max: 1,531 collectType: {532 defaultValue: 0,533 selectValue: 0534 },535 valid: commonValid536 },537 {538 title: "æºèç¹æ°æ®",539 valueKey: "nodeData",540 min: 1,541 max: 1,542 collectType: {543 defaultValue: 1,544 selectValue: 1545 },546 valid: commonValid547 },548 {549 title: "ç®æ èç¹",550 valueKey: "tarNode",551 min: 1,552 max: 1,553 collectType: {554 defaultValue: 0,555 selectValue: 0556 },557 valid: commonValid558 },559 {560 title: "ç®æ èç¹ç±»å«",561 valueKey: "tarNodeType",562 max: 1,563 collectType: {564 defaultValue: 0,565 selectValue: 0566 },567 valid: commonValid568 },569 {570 title: "ç®æ èç¹æ°æ®",571 valueKey: "tarNodeData",572 min: 1,573 max: 1,574 collectType: {575 defaultValue: 1,576 selectValue: 1577 },578 valid: commonValid579 },580 {581 title: "å
³ç³»",582 valueKey: "relation",583 max: 1,584 collectType: {585 defaultValue: 0,586 selectValue: 0587 },588 valid: commonValid589 }590 ]591 },592 {593 type: "sankey",594 name: "æ¡åºå¾",595 iconClass: "layout-sankey",596 cells: [597 {598 title: "æ¥æº",599 valueKey: "node",600 min: 1,601 max: 1,602 collectType: {603 defaultValue: 0,604 selectValue: 0605 },606 valid: commonValid607 },608 {609 title: "ç®æ ",610 valueKey: "target",611 min: 1,612 max: 1,613 collectType: {614 defaultValue: 0,615 selectValue: 0616 },617 valid: commonValid618 },619 {620 title: "ææ ",621 valueKey: "counter",622 min: 1,623 max: 1,624 collectType: {625 defaultValue: 1,626 selectValue: 1627 },628 valid: commonValid629 }630 ]631 },632 {633 type: "themeriver",634 iconClass: "layout-themeriver",635 name: "æ²³æµå¾",636 cells: [637 {638 title: "xè½´",639 valueKey: "xAxis",640 min: 1,641 max: 4,642 collectType: {643 defaultValue: 0,644 selectValue: 0645 },646 valid: commonValid647 },648 {649 title: "ç³»å",650 valueKey: "series",651 max: 1,652 collectType: {653 defaultValue: 0,654 selectValue: 0655 },656 valid: commonValid657 },658 {659 title: "ææ ",660 valueKey: "counter",661 min: 1,662 max: 5,663 collectType: {664 defaultValue: 1,665 selectValue: 1666 },667 valid: commonValid668 }669 ]670 },671 {672 type: "heatMap",673 iconClass: "layout-heat",674 name: "çåå¾å°å¾",675 cells: [676 {677 title: "ç»åº¦",678 valueKey: "lng",679 allowFieldTypes: ["number"],680 min: 1,681 max: 1,682 collectType: {683 defaultValue: 0,684 selectValue: 0685 },686 tip: "å¯æå
¥1个æ°å¼å段",687 valid: commonValid688 },689 {690 title: "纬度",691 valueKey: "lat",692 allowFieldTypes: ["number"],693 min: 1,694 max: 1,695 collectType: {696 defaultValue: 0,697 selectValue: 0698 },699 tip: "å¯æå
¥1个æ°å¼å段",700 valid: commonValid701 },702 {703 title: "ææ ",704 valueKey: "counter",705 allowFieldTypes: ["number"],706 min: 1,707 max: 1,708 collectType: {709 defaultValue: 1,710 selectValue: 2711 },712 valid: commonValid713 }714 ]715 },716 {717 type: "markerMap",718 iconClass: "layout-marker",719 name: "æ è®°å°å¾",720 cells: [721 {722 title: "å称",723 valueKey: "name",724 max: 1,725 collectType: {726 defaultValue: 0,727 selectValue: 0728 },729 valid: commonValid730 },731 {732 title: "ç»åº¦",733 valueKey: "lng",734 allowFieldTypes: ["number"],735 min: 1,736 max: 1,737 collectType: {738 defaultValue: 0,739 selectValue: 0740 },741 tip: "å¯æå
¥1个æ°å¼å段",742 valid: commonValid743 },744 {745 title: "纬度",746 valueKey: "lat",747 allowFieldTypes: ["number"],748 min: 1,749 max: 1,750 collectType: {751 defaultValue: 0,752 selectValue: 0753 },754 tip: "å¯æå
¥1个æ°å¼å段",755 valid: commonValid756 },757 {758 title: "æ¾ç¤ºä¿¡æ¯",759 valueKey: "info",760 max: 5,761 collectType: {762 defaultValue: 0,763 selectValue: 2764 },765 valid: commonValid766 }767 ]768 },769 {770 type: "routeMap",771 iconClass: "layout-route",772 name: "路线å°å¾",773 cells: [774 {775 title: "路线å称",776 valueKey: "routeName",777 min: 1,778 max: 1,779 collectType: {780 defaultValue: 0,781 selectValue: 0782 },783 valid: commonValid784 },785 {786 title: "路线信æ¯",787 valueKey: "routeSeries",788 max: 1,789 collectType: {790 defaultValue: 0,791 selectValue: 0792 },793 valid: commonValid794 },795 {796 title: "ç»åº¦",797 valueKey: "lng",798 allowFieldTypes: ["number"],799 min: 1,800 max: 1,801 collectType: {802 defaultValue: 0,803 selectValue: 0804 },805 tip: "å¯æå
¥1个æ°å¼å段",806 valid: commonValid807 },808 {809 title: "纬度",810 valueKey: "lat",811 allowFieldTypes: ["number"],812 min: 1,813 max: 1,814 collectType: {815 defaultValue: 0,816 selectValue: 0817 },818 tip: "å¯æå
¥1个æ°å¼å段",819 valid: commonValid820 },821 {822 title: "åæ ä¿¡æ¯",823 valueKey: "counter",824 max: 1,825 collectType: {826 defaultValue: 0,827 selectValue: 0828 },829 valid: commonValid830 }831 ]832 },833 {834 type: "migrateMap",835 iconClass: "layout-migrate",836 name: "è¿å¾å°å¾",837 cells: [838 {839 title: "èµ·ç¹å称",840 valueKey: "startName",841 max: 1,842 collectType: {843 defaultValue: 0,844 selectValue: 0845 },846 valid: commonValid847 },848 {849 title: "èµ·ç¹ç»åº¦",850 valueKey: "startLng",851 allowFieldTypes: ["number"],852 min: 1,853 max: 1,854 collectType: {855 defaultValue: 0,856 selectValue: 0857 },858 tip: "å¯æå
¥1个æ°å¼å段",859 valid: commonValid860 },861 {862 title: "èµ·ç¹çº¬åº¦",863 valueKey: "startLat",864 allowFieldTypes: ["number"],865 min: 1,866 max: 1,867 collectType: {868 defaultValue: 0,869 selectValue: 0870 },871 tip: "å¯æå
¥1个æ°å¼å段",872 valid: commonValid873 },874 {875 title: "ç»ç¹å称",876 valueKey: "targetName",877 max: 1,878 collectType: {879 defaultValue: 0,880 selectValue: 0881 },882 valid: commonValid883 },884 {885 title: "ç»ç¹ç»åº¦",886 valueKey: "targetLng",887 allowFieldTypes: ["number"],888 min: 1,889 max: 1,890 collectType: {891 defaultValue: 0,892 selectValue: 0893 },894 tip: "å¯æå
¥1个æ°å¼å段",895 valid: commonValid896 },897 {898 title: "ç»ç¹çº¬åº¦",899 valueKey: "targetLat",900 allowFieldTypes: ["number"],901 min: 1,902 max: 1,903 collectType: {904 defaultValue: 0,905 selectValue: 0906 },907 tip: "å¯æå
¥1个æ°å¼å段",908 valid: commonValid909 },910 {911 title: "æ¾ç¤ºä¿¡æ¯",912 valueKey: "info",913 max: 5,914 collectType: {915 defaultValue: 0,916 selectValue: 2917 },918 valid: commonValid919 }920 ]921 },922 {923 type: "select",924 show: false,925 switch: false,926 name: "åéä¸ææ¡",927 cells: [928 {929 title: "æ°æ®",930 valueKey: "value",931 min: 1,932 max: 1,933 collectType: {934 defaultValue: 0,935 selectValue: 2936 },937 valid: commonValid938 }939 ]940 },941 {942 type: "multiselect",943 show: false,944 switch: false,945 name: "å¤éä¸ææ¡",946 cells: [947 {948 title: "æ°æ®",949 valueKey: "value",950 min: 1,951 max: 1,952 collectType: {953 defaultValue: 0,954 selectValue: 2955 },956 valid: commonValid957 }958 ]959 },960 {961 type: "checkbox",962 show: false,963 switch: false,964 name: "å¤éæ¡",965 cells: [966 {967 title: "æ°æ®",968 valueKey: "value",969 min: 1,970 max: 1,971 collectType: {972 defaultValue: 0,973 selectValue: 2974 },975 valid: commonValid976 }977 ]978 },979 {980 type: "radio",981 show: false,982 switch: false,983 name: "åéæ¡",984 cells: [985 {986 title: "æ°æ®",987 valueKey: "value",988 min: 1,989 max: 1,990 collectType: {991 defaultValue: 0,992 selectValue: 2993 },994 valid: commonValid995 }996 ]997 },998 {999 type: "timeline",1000 show: false,1001 switch: false,1002 name: "å¨ææ°è½´",1003 cells: [1004 {1005 title: "æ°æ®",1006 valueKey: "value",1007 min: 1,1008 max: 1,1009 collectType: {1010 defaultValue: 0,1011 selectValue: 21012 },1013 valid: commonValid1014 }1015 ]1016 },1017 {1018 type: "indexCard",1019 show: false,1020 switch: false,1021 name: "ææ å¡",1022 cells: [1023 {1024 title: "ç±»å«",1025 valueKey: "type",1026 min: 0,1027 max: 1,1028 collectType: {1029 defaultValue: 0,1030 selectValue: 01031 },1032 valid: commonValid1033 },1034 {1035 title: "ææ ",1036 valueKey: "counter",1037 min: 1,1038 max: 2,1039 collectType: {1040 defaultValue: 1,1041 selectValue: 11042 },1043 valid: commonValid1044 }1045 ]1046 }...
order_addcart.js
Source:order_addcart.js
1import { getCartList, getCartCounts, changeCartNum, cartDel} from '../../api/order.js';2import { getProductHot, collectAll } from '../../api/store.js';3import { setFormId } from '../../api/api.js';4const app = getApp();5const util = require('../../utils/util.js');6Page({7 /**8 * 页é¢çåå§æ°æ®9 */10 data: {11 parameter: {12 'navbar': '1',13 'return': '0',14 'title': 'è´ç©è½¦',15 'color': false16 },17 navH: 0,18 cartCount:0,19 goodsHidden:true,20 footerswitch: true,21 host_product: [],22 cartList:[],23 isAllSelect:false,//å
¨é24 selectValue:[],//éä¸çæ°æ®25 selectCountPrice:0.00,26 isGoIndex: true,27 iShidden: false,28 },29 /**30 * çå½å¨æå½æ°--çå¬é¡µé¢å è½½31 */32 onLoad: function (options) {33 var that = this;34 that.setData({35 navH: app.globalData.navHeight36 });37 if (app.globalData.token) that.setData({ iShidden:true});38 },39 /**40 * å
³éææ41 * 42 */43 onCloseAuto: function () {44 this.setData({ iShidden: true });45 },46 subDel:function (event) {47 var formId = event.detail.formId, that = this, selectValue = that.data.selectValue;48 setFormId(formId);49 if (selectValue.length > 0) 50 cartDel(selectValue).then(res=>{51 that.getCartList();52 that.getCartNum();53 });54 else 55 return app.Tips({ title:'请éæ©äº§å'});56 },57 getSelectValueProductId:function(){58 var that = this;59 var validList = that.data.cartList.valid;60 var selectValue = that.data.selectValue;61 var productId = [];62 if (selectValue.length > 0){ for (var index in validList){if(that.inArray(validList[index].id, selectValue)) { productId.push(validList[index].product_id);}}};63 return productId;64 },65 subCollect: function (event){66 var formId = event.detail.formId, that = this, selectValue = that.data.selectValue;67 setFormId(formId);68 if (selectValue.length > 0) {69 var selectValueProductId = that.getSelectValueProductId();70 collectAll(that.getSelectValueProductId().join(',')).then(res=>{71 return app.Tips({title:res.msg,icon:'success'});72 }).catch(err=>{73 return app.Tips({ title: err });74 });75 } else {76 return app.Tips({ title:'请éæ©äº§å'});77 }78 },79 subOrder: function (event){80 var formId = event.detail.formId, that = this, selectValue = that.data.selectValue;81 setFormId(formId);82 if (selectValue.length > 0){83 wx.navigateTo({url:'/pages/order_confirm/index?cartId=' + selectValue.join(',')});84 }else{85 return app.Tips({ title:'请éæ©äº§å'});86 }87 },88 checkboxAllChange: function (event){89 var value = event.detail.value;90 if (value.length > 0) { this.setAllSelectValue(1)}91 else { this.setAllSelectValue(0) }92 },93 setAllSelectValue:function(status){94 var that = this;95 var selectValue = [];96 var valid = that.data.cartList.valid;97 if (valid.length > 0) {98 for (var index in valid) {99 if (status == 1){100 valid[index].checked = true;101 selectValue.push(valid[index].id);102 }else valid[index].checked = false;103 }104 var validData = "cartList.valid";105 that.setData({106 [validData]: valid,107 selectValue: selectValue,108 });109 that.switchSelect();110 }111 },112 checkboxChange: function (event){113 var that = this;114 var value = event.detail.value;115 var valid = this.data.cartList.valid;116 for (var index in valid){117 if (that.inArray(valid[index].id, value)) valid[index].checked = true;118 else valid[index].checked = false;119 }120 var validData = "cartList.valid";121 this.setData({ 122 [validData]: valid,123 isAllSelect: value.length == this.data.cartList.valid.length,124 selectValue: value,125 })126 this.switchSelect();127 },128 inArray:function(search, array){129 for (var i in array) { if (array[i] == search) { return true; } }130 return false;131 },132 switchSelect:function(){133 var that = this;134 var validList = that.data.cartList.valid;135 var selectValue = that.data.selectValue;136 var selectCountPrice = 0.00;137 if (selectValue.length < 1) { that.setData({ selectCountPrice: selectCountPrice }); }138 else{139 for (var index in validList){140 if (that.inArray(validList[index].id, selectValue)){141 selectCountPrice = Number(selectCountPrice) + Number(validList[index].cart_num) * Number(validList[index].truePrice)142 }143 }144 that.setData({ selectCountPrice: selectCountPrice.toFixed(2) });145 }146 },147 subCart:function(event){148 var that = this;149 var status = false;150 var index = event.currentTarget.dataset.index;151 var item = that.data.cartList.valid[index];152 console.log(item);153 item.cart_num = item.cart_num - 1;154 if (item.cart_num < 1) status = true;155 if (item.cart_num <= 1) { 156 item.cart_num = 1;157 item.numSub = true; 158 } else { item.numSub = false;item.numAdd = false; }159 if (false == status) {160 that.setCartNum(item.id, item.cart_num, function (data) {161 var itemData = "cartList.valid[" + index + "]";162 that.setData({ [itemData]: item });163 that.switchSelect();164 });165 }166 },167 addCart: function (event) {168 var that = this;169 var index = event.currentTarget.dataset.index;170 var item = that.data.cartList.valid[index];171 item.cart_num = item.cart_num + 1;172 var productInfo = item.productInfo;173 if (productInfo.hasOwnProperty('attrInfo') && item.cart_num >= item.productInfo.attrInfo.stock) {174 item.cart_num = item.productInfo.attrInfo.stock;175 item.numAdd = true;176 item.numSub = false; 177 } else if (item.cart_num >= item.productInfo.stock) {178 item.cart_num = item.productInfo.stock;179 item.numAdd = true;180 item.numSub = false; 181 } else { item.numAdd = false; item.numSub = false; }182 that.setCartNum(item.id, item.cart_num, function (data) {183 var itemData = "cartList.valid[" + index + "]";184 that.setData({ [itemData]: item });185 that.switchSelect();186 });187 },188 setCartNum(cartId, cartNum, successCallback) {189 var that = this;190 changeCartNum(cartId, cartNum).then(res=>{191 successCallback && successCallback(res.data);192 });193 },194 getCartNum: function () {195 var that = this;196 getCartCounts().then(res=>{197 that.setData({ cartCount: res.data.count });198 });199 },200 getCartList: function () {201 var that = this;202 getCartList().then(res=>{203 var cartList = res.data;204 var valid = cartList.valid;205 var numSub = [{ numSub: true }, { numSub: false }];206 var numAdd = [{ numAdd: true }, { numAdd: false }];207 if (valid.length > 0) {208 for (var index in valid) {209 if (valid[index].cart_num == 1) { valid[index].numSub = true; }210 else { valid[index].numSub = false; }211 var productInfo = valid[index].productInfo;212 if (productInfo.hasOwnProperty('attrInfo') && valid[index].cart_num == valid[index].productInfo.attrInfo.stock) {213 valid[index].numAdd = true;;214 } else if (valid[index].cart_num == valid[index].productInfo.stock) {215 valid[index].numAdd = true;;216 } else { valid[index].numAdd = false; }217 valid[index].checked = false;218 }219 }220 that.setData({ cartList: cartList, goodsHidden: cartList.valid.length <= 0 ? false : true });221 that.switchSelect();222 });223 },224 getHostProduct: function () {225 var that = this;226 getProductHot().then(res=>{227 that.setData({ host_product: res.data });228 });229 },230 goodsOpen:function(){231 var that = this;232 that.setData({233 goodsHidden: !that.data.goodsHidden234 })235 },236 manage:function(){237 var that = this;238 that.setData({239 footerswitch: !that.data.footerswitch240 })241 },242 /**243 * çå½å¨æå½æ°--çå¬é¡µé¢å次渲æå®æ244 */245 onReady: function () {246 },247 onLoadFun: function () {248 this.getHostProduct();249 this.getCartList();250 this.getCartNum();251 },252 /**253 * çå½å¨æå½æ°--çå¬é¡µé¢æ¾ç¤º254 */255 onShow: function () {256 if (app.globalData.isLog == true) {257 this.getHostProduct();258 this.getCartList();259 this.getCartNum();260 this.setData({261 goodsHidden: true,262 footerswitch: true,263 host_product: [],264 cartList: [],265 isAllSelect: false,//å
¨é266 selectValue: [],//éä¸çæ°æ®267 selectCountPrice: 0.00,268 cartCount: 0,269 iShidden:true270 });271 }272 },273 unsetCart:function(){274 let that=this,ids=[];275 for (var i = 0, len = that.data.cartList.invalid.length;i < len;i++){276 ids.push(that.data.cartList.invalid[i].id);277 }278 cartDel(ids).then(res=>{279 app.Tips({ title: 'æ¸
é¤æå' });280 that.setData({ 'cartList.invalid': [] });281 }).catch(res=>{282 });283 },284 /**285 * çå½å¨æå½æ°--çå¬é¡µé¢éè286 */287 onHide: function () {288 },289 /**290 * çå½å¨æå½æ°--çå¬é¡µé¢å¸è½½291 */292 onUnload: function () {293 },294 /**295 * 页é¢ç¸å
³äºä»¶å¤çå½æ°--çå¬ç¨æ·ä¸æå¨ä½296 */297 onPullDownRefresh: function () {298 },...
public.js
Source:public.js
1export const allSelectStatus = [2 "upstreamChannelStatus", "configStatus", "dictStatus", "operatorStatus", 3 "roleStatus", "appStatus", "regionStatus", "userStatus", "configStatus", 4 "dictStatus", "configStatus", "taskStatus", "typeStatus"5]6export const allSelectMessageStatus = ["smsSendStatus"]7export const allSelectTaskStatus = ["taskStatus"]8export const supportCustomSign = ["supportCustomSign", ]9export const supportQueryBalance = ["supportQueryBalance", ]10export const allUserType = ["userType" ]11export const allOperatorSex = ["operatorSex" ]12export const allOperatorLevel = ["operatorLevel" ]13export const allResetType = ["resetType" ]14export const allDictLevel = ["dictLevel" ]15export const allRegionGroupCode = ["regionGroupCode" ]16export const hiddenAllId = ["id"]17export const regionGroupCode = [18 {selectText: 'é»è®¤', selectValue: 'defalut' },19 {selectText: 'å
¶ä»', selectValue: '' }20];21export const resetType = [22 {selectText: 'å
¨å±', selectValue: 'default' },23 {selectText: 'æéç½®', selectValue: 'month' },24 {selectText: 'æ¥éç½®', selectValue: 'day' },25 {selectText: 'æ¶éç½®', selectValue: 'hour' }26];27export const dictLevel = [28 {selectText: 'å
¨å±', selectValue: 'whole' },29 {selectText: 'åºç¨', selectValue: 'app' }30];31export const operatorLevel = [32 {selectText: 'å½å±ç®¡çå', selectValue: 'belonging_admin' },33 {selectText: 'æ®éæä½å', selectValue: 'ordinary_operator' }34];35export const operatorSex = [36 {selectText: 'ç·', selectValue: 'male' },37 {selectText: '女', selectValue: 'female' }38];39export const userType = [40 {selectText: 'å
¨é¨', selectValue: '' },41 {selectText: 'æ¯æå¹³å°æä½äººå', selectValue: 'operation_supplier' }42];43export const queryStatus = [44 {selectText: 'å
¨é¨', selectValue: '' },45 {selectText: 'å¯ç¨', selectValue: 'enabled' },46 {selectText: 'ç¦ç¨', selectValue: 'disabled' }47];48export const smsSendStatus = [49 {selectText: 'å
¨é¨', selectValue: '' },50 {selectText: 'æå', selectValue: 'success' },51 {selectText: '失败', selectValue: 'fail' }52];53export const taskStatus = [54 {selectText: 'å
¨é¨', selectValue: '' },55 {selectText: 'æ£å¸¸', selectValue: 'default' },56 {selectText: 'æå', selectValue: 'paused' }57];58export const querySupport = [59 {selectText: 'å
¨é¨', selectValue: '' },60 {selectText: 'æ¯æ', selectValue: 'support' },61 {selectText: 'ä¸æ¯æ', selectValue: 'not_support' }62];63export const queryAddOrEditStatus = [64 {selectText: 'å¯ç¨', selectValue: 'enabled' },65 {selectText: 'ç¦ç¨', selectValue: 'disabled' }66];67export const queryAddOrEditSupport = [68 {selectText: 'æ¯æ', selectValue: 'support' },69 {selectText: 'ä¸æ¯æ', selectValue: 'not_support' }70];71export const menuShowType = [72 { selectText: 'æ¾ç¤º', selectValue: 'display' },73 { selectText: 'éè', selectValue: 'hide' }74];75export const menuStatus = [76 { selectText: 'å¯ç¨', selectValue: 'enabled' },77 { selectText: 'ç¦ç¨', selectValue: 'disabled' }78];79export const menuType = [80 { selectText: 'èå', selectValue: 'menu' },81 { selectText: 'ç®å½', selectValue: 'catalog' },82 { selectText: 'æé®', selectValue: 'button' }83];84export const in_array = (arr, element) => {85 for (let i = 0; i < arr.length; i++) {86 if (arr[i] == element) {87 return true;88 }89 }90 return false;...
Using AI Code Generation
1import { selectValue } from 'ng-mocks';2import { ComponentFixture, TestBed } from '@angular/core/testing';3import { AppComponent } from './app.component';4import { FormsModule } from '@angular/forms';5describe('AppComponent', () => {6 let component: AppComponent;7 let fixture: ComponentFixture<AppComponent>;8 beforeEach(async () => {9 await TestBed.configureTestingModule({10 imports: [FormsModule],11 }).compileComponents();12 });13 beforeEach(() => {14 fixture = TestBed.createComponent(AppComponent);15 component = fixture.componentInstance;16 fixture.detectChanges();17 });18 it('should create', () => {19 expect(component).toBeTruthy();20 });21 it('should select value', () => {22 selectValue(fixture, 'select', '2');23 expect(component.selectedValue).toEqual('2');24 });25});26import { Component } from '@angular/core';27@Component({28})29export class AppComponent {30 selectedValue = '';31 title = 'ng-mocks';32 { value: 1, title: 'First' },33 { value: 2, title: 'Second' },34 { value: 3, title: 'Third' },35 ];36}37 <h1>{{ title }}</h1>38 <select class="form-control" [(ngModel)]="selectedValue">39 <option *ngFor="let option of options" [value]="option.value">{{ option.title }}</option>40.container {41 width: 50%;42 margin: 0 auto;43 padding: 20px;44 border: 1px solid #ccc;45 border-radius: 5px;46}47import { ComponentFixture, TestBed } from '@angular/core/testing';48import { AppComponent } from './app.component';49describe('AppComponent', () => {50 let component: AppComponent;51 let fixture: ComponentFixture<AppComponent>;52 beforeEach(async () => {53 await TestBed.configureTestingModule({54 }).compileComponents();55 });56 beforeEach(() => {57 fixture = TestBed.createComponent(AppComponent);58 component = fixture.componentInstance;59 fixture.detectChanges();60 });61 it('should create', () => {
Using AI Code Generation
1import { selectValue } from 'ng-mocks';2describe('TestComponent', () => {3 let component: TestComponent;4 let fixture: ComponentFixture<TestComponent>;5 beforeEach(() => {6 TestBed.configureTestingModule({7 });8 fixture = TestBed.createComponent(TestComponent);9 component = fixture.componentInstance;10 });11 it('should select value', () => {12 selectValue(fixture, 'select', 'value');13 expect(component.value).toEqual('value');14 });15});16@Component({17 <select (change)="onSelect($event)">18})19export class TestComponent {20 value = '';21 onSelect(event: Event) {22 this.value = (event.target as HTMLSelectElement).value;23 }24}25<select (change)="onSelect($event)">26import { ComponentFixture, TestBed } from '@angular/core/testing';27import { TestComponent } from './test.component';28describe('TestComponent', () => {29 let component: TestComponent;30 let fixture: ComponentFixture<TestComponent>;31 beforeEach(() => {32 TestBed.configureTestingModule({33 });34 fixture = TestBed.createComponent(TestComponent);35 component = fixture.componentInstance;36 });37 it('should select value', () => {38 const select = fixture.debugElement.query(By.css('select'));39 select.triggerEventHandler('change', { target: { value: 'value' } });40 expect(component.value).toEqual('value');41 });42});43import { Component } from '@angular/core';44@Component({45 <select (change)="onSelect($event)">46})47export class TestComponent {48 value = '';49 onSelect(event: Event) {50 this.value = (event.target as HTMLSelectElement).value;51 }52}53<select (change)="onSelect($event)">
Using AI Code Generation
1import { selectValue } from 'ng-mocks';2import { MyComponent } from './my.component';3import { ComponentFixture, TestBed } from '@angular/core/testing';4import { ReactiveFormsModule } from '@angular/forms';5describe('MyComponent', () => {6 let component: MyComponent;7 let fixture: ComponentFixture<MyComponent>;8 beforeEach(async () => {9 await TestBed.configureTestingModule({10 imports: [ReactiveFormsModule],11 }).compileComponents();12 });13 beforeEach(() => {14 fixture = TestBed.createComponent(MyComponent);15 component = fixture.componentInstance;16 fixture.detectChanges();17 });18 it('should create', () => {19 expect(component).toBeTruthy();20 });21 it('should select value', () => {22 selectValue(fixture, 'select', '2');23 expect(component.form.get('select')?.value).toEqual('2');24 });25});26import { Component } from '@angular/core';27import { FormControl, FormGroup } from '@angular/forms';28@Component({29})30export class MyComponent {
Using AI Code Generation
1import { selectValue } from 'ng-mocks';2import { Component } from '@angular/core';3import { ComponentFixture, TestBed } from '@angular/core/testing';4@Component({5 (ngModelChange)="onChange($event)"6})7class TestComponent {8 value: string;9 onChange(value: string) {10 this.value = value;11 }12}13describe('TestComponent', () => {14 let component: TestComponent;15 let fixture: ComponentFixture<TestComponent>;16 beforeEach(async () => {17 await TestBed.configureTestingModule({18 }).compileComponents();19 });20 beforeEach(() => {21 fixture = TestBed.createComponent(TestComponent);22 component = fixture.componentInstance;23 fixture.detectChanges();24 });25 it('should change value', () => {26 selectValue(fixture, '2');27 expect(component.value).toBe('2');28 });29});30import { selectValue } from 'ng-mocks';31import { Component } from '@angular/core';32import { ComponentFixture, TestBed } from '@angular/core/testing';33@Component({34})35class TestComponent {}36describe('TestComponent', () => {37 let component: TestComponent;38 let fixture: ComponentFixture<TestComponent>;39 beforeEach(async () => {40 await TestBed.configureTestingModule({41 }).compileComponents();42 });43 beforeEach(() => {44 fixture = TestBed.createComponent(TestComponent);45 component = fixture.componentInstance;46 fixture.detectChanges();47 });48 it('should change value', () => {49 selectValue(fixture, '2');50 expect(component.value).toBe('2');51 });52});
Using AI Code Generation
1import { selectValue } from 'ng-mocks';2import { TestBed } from '@angular/core/testing';3import { AppComponent } from './app.component';4import { ComponentFixture } from '@angular/core/testing';5import { By } from '@angular/platform-browser';6import { tick } from '@angular/core/testing';7import { fakeAsync } from '@angular/core/testing';8describe('AppComponent', () => {9 let component: AppComponent;10 let fixture: ComponentFixture<AppComponent>;11 beforeEach(async () => {12 await TestBed.configureTestingModule({13 })14 .compileComponents();15 });16 beforeEach(() => {17 fixture = TestBed.createComponent(AppComponent);18 component = fixture.componentInstance;19 fixture.detectChanges();20 });21 it('should create the app', () => {22 expect(component).toBeTruthy();23 });24 it('should render title', () => {25 const fixture = TestBed.createComponent(AppComponent);26 fixture.detectChanges();27 const compiled = fixture.nativeElement;28 expect(compiled.querySelector('.content span').textContent).toContain('ng-mocks app is running!');29 });30 it('should select the first value of the select', () => {31 selectValue(fixture, 'select', '1');32 tick();33 fixture.detectChanges();34 const select = fixture.debugElement.query(By.css('select')).nativeElement;35 expect(select.value).toBe('1');36 });37 it('should select the second value of the select', () => {38 selectValue(fixture, 'select', '2');39 tick();40 fixture.detectChanges();41 const select = fixture.debugElement.query(By.css('select')).nativeElement;42 expect(select.value).toBe('2');43 });44 it('should select the third value of the select', () => {45 selectValue(fixture, 'select', '3');
Using AI Code Generation
1describe('test', () => {2 it('should be able to get the value of a select', () => {3 const fixture = MockRender(`4 `);5 const select = fixture.debugElement.query(By.css('select'));6 const value = selectValue(select);7 expect(value).toBe('1');8 });9});10describe('test', () => {11 it('should be able to get the value of a select', () => {12 const fixture = MockRender(`13 `);14 const select = fixture.debugElement.query(By.css('select'));15 const value = selectValue(select);16 expect(value).toBe('1');17 });18});19describe('test', () => {20 it('should be able to get the value of a select', () => {21 const fixture = MockRender(`22 `);23 const select = fixture.debugElement.query(By.css('select'));24 const value = selectValue(select);25 expect(value).toBe('1');26 });27});28describe('test', () => {29 it('should be able to get the value of a select', () => {30 const fixture = MockRender(`31 `);32 const select = fixture.debugElement.query(By.css('select'));33 const value = selectValue(select);34 expect(value).toBe('1');35 });36});37describe('test', () => {38 it('should be able to get the value of a select', () => {39 const fixture = MockRender(`
Using AI Code Generation
1var selectValue = ngMocks.selectValue;2var component = ngMocks.find('app');3var form = ngMocks.find('form').componentInstance;4var control = form.form.get('name');5expect(control.value).toEqual('Nancy');6selectValue(component, 'name', 'Bess');7expect(control.value).toEqual('Bess');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!