prj-common-globalservice-legacy.js 15.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
// 项目通用的全局service服务,供不同的controller使用,自定义指令不使用

// 文件下载服务
angular.module('ScheduleApp').factory('FileDownload_g', function() {
    return {
        downloadFile: function (data, mimeType, fileName) {
            var success = false;
            var blob = new Blob([data], { type: mimeType });
            try {
                if (navigator.msSaveBlob)
                    navigator.msSaveBlob(blob, fileName);
                else {
                    // Try using other saveBlob implementations, if available
                    var saveBlob = navigator.webkitSaveBlob || navigator.mozSaveBlob || navigator.saveBlob;
                    if (saveBlob === undefined) throw "Not supported";
                    saveBlob(blob, fileName);
                }
                success = true;
            } catch (ex) {
                console.log("saveBlob method failed with the following exception:");
                console.log(ex);
            }

            if (!success) {
                // Get the blob url creator
                var urlCreator = window.URL || window.webkitURL || window.mozURL || window.msURL;
                if (urlCreator) {
                    // Try to use a download link
                    var link = document.createElement('a');
                    if ('download' in link) {
                        // Try to simulate a click
                        try {
                            // Prepare a blob URL
                            var url = urlCreator.createObjectURL(blob);
                            link.setAttribute('href', url);

                            // Set the download attribute (Supported in Chrome 14+ / Firefox 20+)
                            link.setAttribute("download", fileName);

                            // Simulate clicking the download link
                            var event = document.createEvent('MouseEvents');
                            event.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
                            link.dispatchEvent(event);
                            success = true;

                        } catch (ex) {
                            console.log("Download link method with simulated click failed with the following exception:");
                            console.log(ex);
                        }
                    }

                    if (!success) {
                        // Fallback to window.location method
                        try {
                            // Prepare a blob URL
                            // Use application/octet-stream when using window.location to force download
                            var url = urlCreator.createObjectURL(blob);
                            window.location = url;
                            console.log("Download link method with window.location succeeded");
                            success = true;
                        } catch (ex) {
                            console.log("Download link method with window.location failed with the following exception:");
                            console.log(ex);
                        }
                    }
                }
            }

            if (!success) {
                // Fallback to window.open method
                console.log("No methods worked for saving the arraybuffer, using last resort window.open");
                window.open("", '_blank', '');
            }
        }
    };
});


/**
 * saSelect2指令,根据属性值,动态载入数据,然后支持拼音搜索,点击右边的按钮清除选择并重新载入数据。
 * 1、compile阶段使用的属性如下:
 *      required:用于和表单验证连接,指定成required="true"才有效。
 * 2、link阶段使用的属性如下
 *      model:关联的模型对象
 *      name:表单验证时需要的名字
 *      type:关联的那种数据值(xl/cl/ry)-> 对应线路信息/车辆信息/人员信息,后面有的继续加
 *      modelcolname1:关联的模型字段名字1(一般应该是编码字段)
 *      modelcolname2:关联的模型字段名字2(一般应该是名字字段)
 *      datacolname1;内部数据对应的字段名字1(与模型字段1对应)
 *      datacolname2:内部数据对应的字段名字2(与模型字段2对应)
 *      showcolname:下拉框显示的内部数据字段名(注意:不是模型数据字段名),TODO:以后考虑放动态表达式,并在compile阶段使用
 *      placeholder:select placeholder字符串描述
 *
 * $$pyFilter,内部的filter指令,结合简拼音进行拼音过滤。
 * $$SearchInfoService_g,内部使用的数据服务
 */
// saSelect2指令使用的内部信service
angular.module('ScheduleApp').factory('$$SearchInfoService_g', ['$resource', function($resource) {
    return {
        xl: $resource(
            '/line/:type',
            {order: 'name', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        xlinfo: $resource(
            '/lineInformation/:type',
            {order: 'line.name', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        zd: $resource(
            '/stationroute/stations',
            {order: 'stationCode', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        tcc: $resource(
            '/carpark/:type',
            {order: 'parkCode', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        ry: $resource(
            '/personnel/:type',
            {order: 'personnelName', direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        cl: $resource(
            '/cars/:type',
            {order: "insideCode", direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        ttInfo: $resource(
            '/tic/:type',
            {order: "name", direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        lpInfo: $resource(
            '/gic/ttlpnames',
            {order: "lpName", direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        lpInfo2: $resource(
            '/gic/:type',
            {order: "lpName", direction: 'ASC'},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        cci: $resource(
            '/cci/cars',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }

        ),
        cci2: $resource(
            '/cci/:type',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true,
                    transformResponse: function(rs) {
                        var dst = angular.fromJson(rs);
                        if (dst.status == 'SUCCESS') {
                            return dst.data;
                        } else {
                            return dst; // 业务错误留给控制器处理
                        }
                    }
                }
            }
        ),
        cci3: $resource(
            '/cci/cars2',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }

        ),
        eci: $resource(
            '/eci/jsy',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        eci2: $resource(
            '/eci/spy',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),
        eci3: $resource(
            '/eci/:type',
            {},
            {
                list: {
                    method: 'GET',
                    isArray: true
                }
            }
        ),


        validate: { // remoteValidation指令用到的resource
            gbv1: { // 路牌序号验证
                template: {'xl.id_eq': -1, 'lpNo_eq': 'ddd'},
                remote: $resource(
                    '/gic/validate1',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },
            gbv2: { // 路牌名称验证
                template: {'xl.id_eq': -1, 'lpName_eq': 'ddd'},
                remote: $resource(
                    '/gic/validate2',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },

            cars_zbh: { // 自编号验证
                template: {'insideCode_eq': '-1'}, // 查询参数模版
                remote: $resource( // $resource封装对象
                    '/cars_sc/validate_zbh',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },

            cars_sbbh: { // 验证设备编号
                template: {'equipmentCode_eq': '-1'}, // 查询参数模版
                remote: $resource( // $resource封装对象
                    '/cars_sc/validate_sbbh',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },

            cars_clbh: { // 车辆编号验证
                template: {'carCode_eq': '-1'}, // 查询参数模版
                remote: $resource( // $resource封装对象
                    '/cars_sc/validate_clbh',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },

            cars_cph: { // 车牌号验证
                template: {'carPlate_eq': '-1'}, // 查询参数模版
                remote: $resource( // $resource封装对象
                    '/cars_sc/validate_cph',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },
            cc_cars: { // 车辆不能重复配置
                template: {'xl.id_eq': -1, 'xl.name_eq': '-1', 'cl.id_eq': -1}, // 查询参数模版
                remote: $resource( // $resource封装对象
                    '/cci/validate_cars',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },
            ec_jsy: { // 驾驶员不能重复配置
                template: {'xl.id_eq': -1, 'xl.name_eq': '-1', 'jsy.id_eq': -1}, // 查询参数模版
                remote: $resource( // $resource封装对象
                    '/eci/validate_jsy',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },
            ec_spy: { // 售票员不能重复配置
                template: {'xl.id_eq': -1, 'xl.name_eq': '-1', 'spy.id_eq': -1}, // 查询参数模版
                remote: $resource( // $resource封装对象
                    '/eci/validate_spy',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },

            cde1: { // 车辆设备启用日期验证
                template: {'qyrq': 0, 'xl': 1, 'cl': 1}, // 日期毫秒
                remote: $resource( // $resource封装对象
                    '/cde//validate/qyrq',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },
            ttc1: { // 时刻表名字验证
                template: {'xl.id_eq': -1, 'name_eq': 'ddd'},
                remote: $resource( // $resource封装对象
                    '/tic/validate/equale',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            },
            sheet: { // 时刻表sheet工作区验证
                template: {'filename': '', 'sheetname': '', 'lineid': -1, 'linename': ''},
                remote: $resource( // $resource封装对象
                    '/tidc/validate/sheet',
                    {},
                    {
                        do: {
                            method: 'POST',
                            headers: {
                                'Content-Type': 'application/x-www-form-urlencoded'
                            },
                            transformRequest: function(obj) {
                                var str = [];
                                for (var p in obj) {
                                    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                                }
                                return str.join("&");
                            }
                        }
                    }
                )
            },
            sheetli: { // 时刻表线路标准验证
                template: {'lineinfoid': -1},
                remote: $resource( // $resource封装对象
                    '/tidc/validate/lineinfo',
                    {},
                    {
                        do: {
                            method: 'GET'
                        }
                    }
                )
            }
        }

        //validate: $resource(
        //    '/cars/validate/:type',
        //    {},
        //    {
        //        insideCode: {
        //            method: 'GET'
        //        }
        //    }
        //)



    }
}]);