cuiqian2004
2024-06-11 6be7369a96ac84bbc5dc95f792a180d7b86cc89a
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
<style lang="scss">
    .example {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 150px;
        // background-color: #efefef;
    }
    .transition-button {
        width: 100%;
        flex: 1;
        margin-bottom: 10px;
    }
    .example ::v-deep .transition {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100px;
        height: 100px;
        border-radius: 5px;
        text-align: center;
        // background-color: #4cd964;
        // box-shadow: 0 0 5px 1px rgba(0, 0, 0, 0.2);
    }
    .text {
        font-size: 14px;
        color: #fff;
    }
</style>
<style>
    .content{
        min-height: 100vh;
        background-color: #efefef;
        padding: 1rpx 0rpx;
    }
    .dv_head{
        background-color: #efefef;
    }
    .head_title{
        text-align: center;
        font-size: 19px;
        font-weight: bold;
    }
    .uni-section .uni-section-header{
        display: none !important;
    }
    .dv_content{
        margin: 30rpx;
        padding: 10rpx;
        border-radius: 12rpx;
    }
    .dv_panel{
      background-color:#fff;
      padding: 20rpx;
      margin-top: 20rpx;
      border-radius: 12rpx;
      /* box-shadow: 2rpx 2rpx 2rpx rgba(0, 0, 0, 0.3); */
    }
    .dv_panel:first-child{
        margin: 0;
    }
    .panel_image_uploadlist {
        display: inline-block;
        /* padding: 30rpx 0px 10rpx 0px; */
        vertical-align: middle;
        width: 200rpx;
        height: 200rpx;
        text-align: center;
        line-height: 100%;
        border: 2rpx solid transparent;
        border-radius: 8rpx;
        overflow: hidden;
        background: #fff;
        position: relative;
        /* box-shadow: 0 2rpx 2rpx rgba(0, 0, 0, 0.2);
        margin-right: 8rpx; */
    }
    .panel_image_uploadlist image{
        width: 100%;
        height: 100%;
    }
    .panel_title{
        display: inline-block;
        padding-left: 30rpx;
        vertical-align: middle;
    }
    .panel_title p{
        font-size: 19px;
        font-weight: bold;
    }
    .panel_title span{
        font-size: 14px;
    }
    
</style>
 
<template>
    <view class="content">
        <view class="dv_head">
            <uni-section :title="title">
                <view class="example" :style="{'background-color':param.welcome_page.bkground_color,'height':(param.welcome_page.height+30)+'px'}">
                    <uni-transition ref="ani" custom-class="transition" :duration="duration" :mode-class="modeClass" :styles="styles" :show="show">
                        <image :src="param.welcome_page.img" 
                            :style="{'width':param.welcome_page.width+'px','height':param.welcome_page.height+'px'}"></image>
                    </uni-transition>
                </view>
            </uni-section>
        </view>
        
        <view class="dv_content">
            <view class="dv_panel" v-for="(item,index) in param.catalog" 
              :style="{'background-color':item.bkground_color}" @tap="onViewClick(item)"
            >
                <view class="panel_image_uploadlist">
                    <image :src="item.img"></image>
                </view>
                <view class="panel_title">
                    <p>{{item.title}}</p>
                    <span>{{item.taskQty}}</span>
                </view>
            </view>
            
        </view>
    </view>
</template>
 
<script>
import Base64 from '../../components/js-base64/base64.js'
export default {
  modules:{
    Base64,
  },
  data() {
    return {
      title:'3201首页',
      param: {},
      show: true,
      duration:0,
      modeClass: ['fade', 'slide-left'],
      styles: {
        justifyContent: 'center',
        alignItems: 'center',
        width: '100px',
        height: '100px',
        borderRadius: '5px',
        textAlign: 'center',
        backgroundColor: '#fff',
      },
      wheres:'',
      orderby:'',
    };
  },
  onReady() {
    // console.log(1111);
    // this.$refs.ani.init({
    //     duration: 1000,  //过渡动画持续时间,单位ms    
    //     timingFunction: 'linear',
    //     transformOrigin: '50% 50%',
    //     delay: 500  //动画延迟时间,单位 ms    
    // });
    // this.$refs.ani.step({
    //     // translateX: '50px'
    // },{
    //     duration: 1000,  //过渡动画持续时间,单位ms    
    //     timingFunction: 'linear',
    //     transformOrigin: '50% 50%',
    //     delay: 500  //动画延迟时间,单位 ms    
    // });
    // // 开始执行动画
    // this.$refs.ani.run(()=>{
    //     console.log('动画支持完毕')
    // });
  },
  async onLoad(options) {
    // console.log(options);
    this.duration=2000;
    uni.setNavigationBarTitle({ title: options.titlename}); //设置顶部标题 
    this.$data.title = options.titlename;
    this.$data.param = JSON.parse(options.param);
    console.log(this.$data.param);
    //加载初始界面
    if(this.$data.param.welcome_page){
      this.$data.styles.width = this.$data.param.welcome_page.width+'px';
      this.$data.styles.height = this.$data.param.welcome_page.height+'px';
      this.$data.styles.backgroundColor = this.$data.param.welcome_page.bkground_color;
      
      this.$data.param.welcome_page.img = this.$data.param.welcome_page.img.replace(/ /g,'+');
      this.$data.param.welcome_page.width = parseInt(this.$data.param.welcome_page.width);
      this.$data.param.welcome_page.height = parseInt(this.$data.param.welcome_page.height);
      this.$data.param.catalog.forEach(async (ele,index) => {
        ele.img = ele.img.replace(/ /g,'+');
        ele.taskQty=0;
        await this.appGetInfo(ele.function_def_id,index);
      });
    }
    
  },    
  methods: {
    //获取功能点信息
    appGetInfo(appid,index){
        var $this = this;
        var json ={
            app_id: [appid]
        };
        this.$store.dispatch('appGetInfo',json).then(async success=>{
            // console.log(success);
            if (success.err_code == 0) {
                var app = success.result[0];
                var paramStr = app.param;
                var appName = app.name;
                var defCode = app.def_code;
                var param = "";
                if(paramStr){
                    //mobox2的param是json字符串
                    param = paramStr.replace(/\\/g,"");
                    //mobox3的param是base64字符串
                    if(!paramStr.includes('"')) param = Base64.decode(paramStr);
                }      
                if(!param){
                    uni.showModal({title:"提示",content:defCode+"该功能点未配置参数,请重新配置参数!",showCancel:false,confirmText:"取消"});
                    return;
                }
                this.$data.param.catalog[index].param=param;
                this.$data.param.catalog[index].appName=appName;
                param = JSON.parse(param);
                
                $this.orderby = param.Order?param.Order:'T_CREATE Desc';
                if(param.Query_Event){
                    await $this.onSearChange(param.DataCls.id,param.Query_Event.id,index);
                } else{
                  $this.wheres = param.Condition;
                  await $this.loadDataGetList(param.DataCls.id,index);
                }
            }else{
                uni.showModal({title:"提示",content:success.msg,showCancel:false,confirmText:"取消"});
            }
        }).catch(ex=>{
            // console.log(ex);
            uni.showModal({title:"错误",content:ex.errMsg,showCancel:false,confirmText:"取消"});
        });
    },
    // 执行查询事件
    async onSearChange(clsid,eventid,index) {
     try {
        if (eventid) {
           var $this = this;
           var dataInfo={
            ed_type: 0,
            start_transaction: true,
            class_id: clsid,
            event_id: eventid,
          };
           this.$store.dispatch('runCustomEvent',dataInfo).then(ret=>{
               console.log(ret);
               if (ret.err_code == 0) {
                 var result = ret.result; 
                 if (result.ret != 0) {
                     var tip = result.err_info ? typeof result.err_info == 'string' ? result.err_info : result.err_info.join('<br/>') : '';
                     if (result.ret == 801) uni.showModal({title:'提示',content:tip,showCancel:false,confirmText:"取消"});
                     else uni.showModal({title:'提示',content:tip+',提示:'+result.ret,showCancel:false,confirmText:"取消"});
                     return false;
                 }else{
                     var tip = result.info ? typeof result.info == 'string' ? result.info : result.info.join('<br/>') : '';
                     if (tip) uni.showModal({title:'提示',content:tip,showCancel:false,confirmText:"取消"});
                 
                     if(result.result_type == 0 && result.action){
                         result.action.forEach(item=>{
                             if(item.action_type == "set_query_condition"){ 
                                 var value = item.value;
                                 $this.wheres = value.condition;
                                 $this.orderby = value.order?value.order:$this.orderby;
                                 $this.loadDataGetList(clsid,index);
                             } 
                            
                        });
                     }else{
                         // this.detail2StyleDefList=[];
                         if(result.info){
                             uni.showModal({title:"提示",content:result.info,showCancel:false,confirmText:"取消"});
                         }
                     }
                 }
                   
               }else{
                   uni.showModal({title:"错误1",content:ret.err_msg,showCancel:false,confirmText:"取消"});
               }
           }).catch(ex=>{
               // console.log(ex);
               uni.showModal({title:"错误1.1",content:ex.errMsg,showCancel:false,confirmText:"取消"});
           });
         }
     } catch (ex) {
         var tip = typeof ex == "string" ? ex : ex.message;
         uni.showModal({title:"错误1.2",content:"执行“查询事件”事件失败:" + tip,showCancel:false,confirmText:"取消"});
         
     }
    },
    //查询数据类数据信息
    async loadDataGetList(clsid,index){   
      try{
        //条件查询
        var condition = this.wheres;
        // console.log(condition);
        // console.log(this.orderby);
        var $this = this;
        var dataInfo={
            class_id: clsid,
            attrs: [],
            condition: this.toWhereBase64String(""+ condition +""), 
            prj_rel_type: "",
            order_by: this.orderby,
            page_size: 99999,
            page: 1,
            query_id: '',
        };
        this.$store.dispatch('dataObjQuery',dataInfo).then(ret=>{
            // console.log(ret);
            if (ret.err_code == 0) {
                if(ret.result){
                    $this.$data.param.catalog[index].taskQty=ret.result.obj_list.length;
                    // console.log($this.$data.param.catalog[index]);
                    var catalog = JSON.parse(JSON.stringify($this.$data.param.catalog));
                    $this.$data.param.catalog=[];
                    $this.$data.param.catalog=catalog;
                }
            }else{
                uni.showModal({title:"错误2",content:ret.err_msg,showCancel:false,confirmText:"取消"});
            }
        }).catch(ex=>{
            // console.log(ex);
            uni.showModal({title:"错误2.1",content:ex.errMsg,showCancel:false,confirmText:"取消"});
        });
      } catch (ex) {
        var tip = typeof ex == "string" ? ex : ex.message;
        uni.showModal({title:"错误2.2",content:tip,showCancel:false,confirmText:"取消"});
      }
    },
    
    //点击条目打开3200
    onViewClick(data){
        if(!data.function_def_id){
            uni.showModal({title:"提示",content:"该条目未关联功能点!",showCancel:false,confirmText:"取消"});
            return;
        }
        var $this = this;
        uni.navigateTo({
            url:'../modal/3200?param='+data.param+"&titlename="+data.appName,
            events: {
                // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
                view_3201: function(data) {
                    console.log(data);
                    //刷新当前页面
                    // location.reload();
                    // uni.redirectTo({
                    //     url:'../modal/3201?param='+JSON.stringify($this.$data.param)+"&titlename="+$this.$data.title
                    // });
                    $this.$data.param.catalog.forEach(async (ele,index) => {
                        ele.taskQty=0;
                        await $this.appGetInfo(ele.function_def_id,index);
                    });
                }
            },
        });
    },            
    
    
    cancel(e){ //取消
        uni.navigateBack({
            delta:1 ,//返回层数,2则上上页
        });
    },
    /**
     * 只支持["column1='A' or column2='B'", "column3='C' and column4='D'", "column5='E'"]这种格式
     * {
     *     "model": 0 / 1,
     *     "condition":
     *     [
     *         [
     *             { },
     *             { },
     *             { }
     *         ],
     *         [
     *             { }
     *         ],
     *         [
     *             { }
     *         ]
     *     ]
     * }
     */
    toWhereBase64String(list) {
        if (typeof list == 'string') list = [list]
        var sql = []
        var seps = [' not in', ' in', '<>', '!=', '<=', '>=', '<', '=', '>', ' like']
        list.forEach(ls => {
            var where = ls.trim()
            if (where.startsWith('(') && where.endsWith(')')) where = where.replace(/^\(/, '').replace(/\)$/, '')
            if (where.toLowerCase().includes(' and ')) {
                // 二级and放在第一级数组中
                where.split(/ and /i).forEach(li => {
                    var l = li.trim()
                    if (l.startsWith('(') && l.endsWith(')')) l = l.replace(/^\(/, '').replace(/\)$/, '')
                    var sep = ''
                    for (var i = 0; i < seps.length; i++) {
                        if (l.toLowerCase().includes(seps[i])) {
                            sep = seps[i]
                            break
                        }
                    }
                    if (sep) {
                        var values = l.split(new RegExp(sep, 'i'))
                        var field = values[0]?.trim().replace(/^\[/, '').replace(/\]$/, '')
                        var value = ''
                        var op = sep.trim()
 
                        if ([' in', ' not in'].includes(sep) && values[1]?.toLowerCase().includes('select ') && values[1]?.toLowerCase().includes(' from ')) {
                            value = l.replace(field, '').replace(/^\s*(in|not in)\s*/i, '').trim()
                            if (value.startsWith('(') && value.endsWith(')')) value = value.replace(/^\(/, '').replace(/\)$/, '').trim()
                        }
                        else {
                            value = values[1]?.trim().replace(/^\'/, '').replace(/\'$/, '')
 
                            if (['in', 'not in'].includes(op)) {
                                value = value.replace(/^\(/, '').replace(/\)$/, '')
                                value = value.split(',').map(v => v.trim().replace(/^\'/, '').replace(/\'$/, ''))
                            }
                        }
                        sql.push([{ field, value, op }])
                    }
                })
            }
            else if (where.toLowerCase().includes(' or ')) {
                // 二级or放在第二级同一组数组中
                var s = []
                where.split(/ or /i).forEach(li => {
                    var l = li.trim()
                    if (l.startsWith('(') && l.endsWith(')')) l = l.replace(/^\(/, '').replace(/\)$/, '')
                    var sep = ''
                    for (var i = 0; i < seps.length; i++) {
                        if (l.toLowerCase().includes(seps[i])) {
                            sep = seps[i]
                            break
                        }
                    }
                    if (sep) {
                        var values = l.split(new RegExp(sep, 'i'))
                        var field = values[0]?.trim().replace(/^\[/, '').replace(/\]$/, '')
                        var value = ''
                        var op = sep.trim()
 
                        if ([' in', ' not in'].includes(sep) && values[1]?.toLowerCase().includes('select ') && values[1]?.toLowerCase().includes(' from ')) {
                            value = l.replace(field, '').replace(/^\s*(in|not in)\s*/i, '').trim()
                            if (value.startsWith('(') && value.endsWith(')')) value = value.replace(/^\(/, '').replace(/\)$/, '').trim()
                        }
                        else {
                            value = values[1]?.trim().replace(/^\'/, '').replace(/\'$/, '')
 
                            if (['in', 'not in'].includes(op)) {
                                value = value.replace(/^\(/, '').replace(/\)$/, '')
                                value = value.split(',').map(v => v.trim().replace(/^\'/, '').replace(/\'$/, ''))
                            }
                        }
                        sql.push([{ field, value, op }])
                    }
                })
                sql.push(s)
            }
            else {
                var li = where
                // 单一查询条件直接放在第一级数组中
                var l = li.trim()
                if (l.startsWith('(') && l.endsWith(')')) l = l.replace(/^\(/, '').replace(/\)$/, '')
                var sep = ''
                for (var i = 0; i < seps.length; i++) {
                    if (l.toLowerCase().includes(seps[i])) {
                        sep = seps[i]
                        break
                    }
                }
                if (sep) {
                    var values = l.split(new RegExp(sep,'i'))
                    var field = values[0]?.trim().replace(/^\[/, '').replace(/\]$/, '')
                    var value = ''
                    var op = sep.trim()
 
                    if ([' in', ' not in'].includes(sep) && values[1]?.toLowerCase().includes('select ') && values[1]?.toLowerCase().includes(' from ')) {
                        value = l.replace(field, '').replace(/^\s*(in|not in)\s*/i, '').trim()
                        if (value.startsWith('(') && value.endsWith(')')) value = value.replace(/^\(/, '').replace(/\)$/, '').trim()
                    }
                    else {
                        value = values[1]?.trim().replace(/^\'/, '').replace(/\'$/, '')
 
                        if (['in', 'not in'].includes(op)) {
                            value = value.replace(/^\(/, '').replace(/\)$/, '')
                            value = value.split(',').map(v => v.trim().replace(/^\'/, '').replace(/\'$/, ''))
                        }
                    }
                    sql.push([{ field, value, op }])
                }
            }
        })
 
        if (sql.length > 0)
            return Base64.encode(JSON.stringify({
                model: 1,
                condition: sql
            }))
        else
        return ''
    },
    
  },
};
</script>