Procházet zdrojové kódy

优化namespace 最终版

wuxw před 6 roky
rodič
revize
c64cdafff6

+ 1 - 1
WebService/src/main/resources/components/floorPackage/floor-select2/floorSelect2.html

@@ -1,4 +1,4 @@
-<select class="form-control floorSelector">
+<select class="form-control" id = "floorSelector">
     <option value="">请选择楼栋</option>
 
 

+ 7 - 7
WebService/src/main/resources/components/floorPackage/floor-select2/floorSelect2.js

@@ -15,7 +15,7 @@
             floorSelect2Info:{
                 deep: true,
                 handler:function(){
-                    vc.emit('unitSelect2', "transferFloor" ,vc.component.floorSelect2Info);
+                    vc.emit('unitSelect2', "transferFloor" ,this.floorSelect2Info);
                 }
             }
         },
@@ -28,7 +28,7 @@
                  vc.component._initFloorSelect2();
             })*/
            vc.on('floorSelect2','setFloor',function (_param) {
-               $(".floorSelector").val(_param.floorId).select2();
+               $("#floorSelector").val(_param.floorId).select2();
            });
         },
         methods: {
@@ -36,7 +36,7 @@
                 console.log("调用_initFloorSelect2 方法");
                 $.fn.modal.Constructor.prototype.enforceFocus = function () {};
                 $.fn.select2.defaults.set('width', '100%');
-                $('.floorSelector').select2({
+                $('#floorSelector').select2({
                     placeholder: '必填,请选择楼栋',
                     ajax: {
                         url: "/callComponent/floorSelect2/list",
@@ -56,15 +56,15 @@
                             };
                         },
                         processResults: function (data) {
-                            console.log(data, vc.component._filterFloorData(data.apiFloorDataVoList));
+                            console.log(data, this._filterFloorData(data.apiFloorDataVoList));
                             return {
-                                results: vc.component._filterFloorData(data.apiFloorDataVoList)
+                                results: this._filterFloorData(data.apiFloorDataVoList)
                             };
                         },
                         cache: true
                     }
                 });
-                $('.floorSelector').on("select2:select", function (evt) {
+                $('#floorSelector').on("select2:select", function (evt) {
                     //这里是选中触发的事件
                     //evt.params.data 是选中项的信息
                     console.log('select',evt);
@@ -72,7 +72,7 @@
                     this.floorSelect2Info.floorName = evt.params.data.text;
                 });
 
-                $('.floorSelector').on("select2:unselect", function (evt) {
+                $('#floorSelector').on("select2:unselect", function (evt) {
                     //这里是取消选中触发的事件
                     //如配置allowClear: true后,触发
                     console.log('unselect',evt)

+ 5 - 3
WebService/src/main/resources/components/machinePackage/edit-machine/editMachine.html

@@ -63,10 +63,10 @@
                              v-show="editMachineInfo.locationTypeCd == '2000' || editMachineInfo.locationTypeCd == '3000'  ">
                             <label class="col-sm-2 col-form-label">归属楼栋</label>
                             <div class="col-sm-10">
-                                <!--<vc:create name="floorSelect2"
+                                <vc:create name="floorSelect2"
                                            parentModal="editMachineModel"
-
-                                ></vc:create>-->
+                                           namespace="editMachine"
+                                ></vc:create>
                             </div>
                         </div>
                         <div class="form-group row"
@@ -77,6 +77,7 @@
                                            parentModal="editMachineModel"
                                            callBackListener="editMachine"
                                            callBackFunction="notify"
+                                           namespace="editMachine"
                                 ></vc:create>
                             </div>
                         </div>
@@ -88,6 +89,7 @@
                                            parentModal="editMachineModel"
                                            callBackListener="editMachine"
                                            callBackFunction="notify"
+                                           namespace="editMachine"
                                 ></vc:create>
                             </div>
                         </div>

+ 1 - 1
WebService/src/main/resources/components/roomPackage/room-select2/roomSelect2.html

@@ -1,4 +1,4 @@
-<select class="form-control roomSelector">
+<select class="form-control " id="roomSelector">
     <option value="">请选择房屋</option>
 
 

+ 4 - 4
WebService/src/main/resources/components/roomPackage/room-select2/roomSelect2.js

@@ -35,7 +35,7 @@
            });
             vc.on('roomSelect2','setRoom',function (_param) {
                 vc.copyObject(_param, vc.component.roomSelect2Info);
-                $(".roomSelector").val(_param.roomId).select2();
+                $("#roomSelector").val(_param.roomId).select2();
             });
         },
         methods: {
@@ -43,7 +43,7 @@
                 console.log("调用_initRoomSelect2 方法");
                 $.fn.modal.Constructor.prototype.enforceFocus = function () {};
                 $.fn.select2.defaults.set('width', '100%');
-                $('.roomSelector').select2({
+                $('#roomSelector').select2({
                     placeholder: '必填,请选择房屋',
                     ajax: {
                         url: "/callComponent/roomSelect2/listRoom",
@@ -72,7 +72,7 @@
                         cache: true
                     }
                 });
-                $('.roomSelector').on("select2:select", function (evt) {
+                $('#roomSelector').on("select2:select", function (evt) {
                     //这里是选中触发的事件
                     //evt.params.data 是选中项的信息
                     console.log('select',evt);
@@ -80,7 +80,7 @@
                     vc.component.roomSelect2Info.roomNum = evt.params.data.text;
                 });
 
-                $('.roomSelector').on("select2:unselect", function (evt) {
+                $('#roomSelector').on("select2:unselect", function (evt) {
                     //这里是取消选中触发的事件
                     //如配置allowClear: true后,触发
                     console.log('unselect',evt)

+ 1 - 1
WebService/src/main/resources/components/unitPackage/unit-select2/unitSelect2.html

@@ -1,4 +1,4 @@
-<select class="form-control unitSelector">
+<select class="form-control " id="unitSelector">
     <option value="">请选择单元</option>
 
 

+ 3 - 3
WebService/src/main/resources/components/unitPackage/unit-select2/unitSelect2.js

@@ -44,7 +44,7 @@
                 console.log("调用_initUnitSelect2 方法");
                 $.fn.modal.Constructor.prototype.enforceFocus = function () {};
                 $.fn.select2.defaults.set('width', '100%');
-                $('.unitSelector').select2({
+                $('#unitSelector').select2({
                     placeholder: '必填,请选择单元',
                     ajax: {
                         url: "/callComponent/unitSelect2/loadUnits",
@@ -73,7 +73,7 @@
                         cache: true
                     }
                 });
-                $('.unitSelector').on("select2:select", function (evt) {
+                $('#unitSelector').on("select2:select", function (evt) {
                     //这里是选中触发的事件
                     //evt.params.data 是选中项的信息
                     console.log('select',evt);
@@ -81,7 +81,7 @@
                     vc.component.unitSelect2Info.unitName = evt.params.data.text;
                 });
 
-                $('.unitSelector').on("select2:unselect", function (evt) {
+                $('#unitSelector').on("select2:unselect", function (evt) {
                     //这里是取消选中触发的事件
                     //如配置allowClear: true后,触发
                     console.log('unselect',evt)

+ 9 - 10
java110-front/src/main/java/com/java110/front/core/VcCreateProcessor.java

@@ -90,7 +90,9 @@ public class VcCreateProcessor extends AbstractElementTagProcessor {
 
         String namespace = tag.getAttributeValue("namespace");
 
-        return html.replace("this.", namespace + "_");
+        return html.replace("this.", namespace + "_")
+                .replaceAll("(id)+( )*+=+( )*+'", "id='" + namespace + "_")
+                .replaceAll("(id)+( )*+=+( )*+\"", "id=\"" + namespace + "_");
     }
 
     private String dealHtmlJs(IProcessableElementTag tag, String js) {
@@ -101,7 +103,9 @@ public class VcCreateProcessor extends AbstractElementTagProcessor {
 
         String namespace = tag.getAttributeValue("namespace");
 
-        return js.replace("this.", "vc.component."+namespace + "_");
+        return js.replace("this.", "vc.component." + namespace + "_")
+                .replaceAll("(\\$)+( )*+(\\()+( )*+\'+#", "\\$('#" + namespace + "_")
+                .replaceAll("(\\$)+( )*+(\\()+( )*+\"+#", "\\$(\"#" + namespace + "_");
     }
 
 
@@ -246,15 +250,10 @@ public class VcCreateProcessor extends AbstractElementTagProcessor {
     }
 
     public static void main(String[] args) {
-        String js = "(function (vc, vm) {vc.extends({a:'123'})})";
-        int extPos = js.indexOf("vc.extends");
-        String tmpProTypes = js.substring(extPos);
-        int pos = tmpProTypes.indexOf("{") + 1;
-        js = js.substring(0, extPos) + tmpProTypes.substring(0, pos).trim() + "\nnamespace:" + DEFAULT_NAMESPACE + ",\n" + tmpProTypes.substring(pos, tmpProTypes.length());
-        int position = js.indexOf("{");
-        String propsJs = "\n$namespace=" + DEFAULT_NAMESPACE + ";\n";
-        js = new StringBuffer(js).insert(position + 1, propsJs).toString();
+        String js = "123$ ( '#av').val()";
+        js = js.replaceAll("(\\$)+( )*+(\\()+( )*+\'+#", "\\$('#abg_");
 
         System.out.println(js);
+
     }
 }