exp-view-base.tsx 6.3 KB
Newer Older
1
import { useNamespace } from '@ibiz-template/vue-util';
2
import { computed, defineComponent, PropType, ref, watch } from 'vue';
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
import './exp-view-base.scss';
import { IExpBarModel } from '@ibiz-template/model';
import { ListExpViewController } from '@ibiz-template/controller';

export const ExpViewBase = defineComponent({
  name: 'ExpViewBase',
  props: {
    controller: {
      type: Object as PropType<ListExpViewController>,
      required: true,
    },
    expBarModel: {
      type: Object as PropType<IExpBarModel>,
    },
  },
  setup(props) {
    const ns = useNamespace('exp-view');

21 22 23 24 25 26 27 28 29 30 31 32
    const cssVars = ref({});

    watch(
      () => props.expBarModel?.width,
      (newVal, oldVal) => {
        if (newVal !== oldVal && newVal) {
          cssVars.value = ns.cssVarBlock({
            'left-width': `${newVal}px`,
          });
        }
      },
    );
33 34 35 36

    // 是否显示头部
    const isShowHeader = computed(() => {
      return (
37 38
        props.expBarModel?.showTitleBar ||
        props.expBarModel?.enableSearch ||
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
        props.controller.model.toolbar
      );
    });

    return { ns, cssVars, isShowHeader };
  },
  render() {
    const c = this.controller;

    // 外面的插槽同样传给view-layout
    const inheritSlots: IData = {};
    Object.keys(this.$scopedSlots).forEach(key => {
      inheritSlots[key] = (arg: IData) => this.$scopedSlots[key]!(arg);
    });
    return (
      <div class={[this.ns.b()]} style={this.cssVars}>
        <div class={[this.ns.b('left')]}>
          <view-layout
            class={[
              c.complete && this.ns.b(this.controller.model.typeClass),
              c.complete && this.ns.m(this.controller.model.modelClass),
            ]}
            isComplete={c.complete}
            modelData={c.model}
            viewMode={c.modal.mode}
            isLoading={c.viewLoading.isLoading}
            scopedSlots={{
              caption: () => {
                return (
                  <div class={this.ns.b('caption')}>
                    {c.complete && c.model.source.getPSSysImage() ? (
                      [
                        <app-icon
                          class={this.ns.be('caption', 'icon')}
                          icon={c.model.source.getPSSysImage()}
                        ></app-icon>,
                        <span
                          class={this.ns.be('caption', 'text')}
                          title={c.caption}
                        >
                          {c.caption}
                        </span>,
                      ]
                    ) : (
                      <span
                        class={this.ns.be('caption', 'text')}
                        title={c.caption}
                      >
                        {c.caption}
                      </span>
                    )}
                  </div>
                );
              },
              ...inheritSlots,
              default: () => {
                return (
                  <div
                    class={[
                      this.ns.b('exp-bar'),
                      this.ns.is('no-header', !this.isShowHeader),
                    ]}
                  >
                    <div class={this.ns.b('exp-bar-header')}>
                      <div class={this.ns.b('exp-bar-header-left')}>
                        <div
                          class={this.ns.be('exp-bar-header-left', 'caption')}
                        >
107 108
                          {this.expBarModel?.showTitleBar &&
                            (this.expBarModel?.getPSSysImage ? (
109 110 111
                              [
                                <app-icon
                                  class={this.ns.be('caption', 'icon')}
112
                                  icon={this.expBarModel?.getPSSysImage}
113 114 115
                                ></app-icon>,
                                <span
                                  class={this.ns.be('caption', 'text')}
116
                                  title={this.expBarModel?.title}
117
                                >
118
                                  {this.expBarModel?.title}
119 120 121 122 123
                                </span>,
                              ]
                            ) : (
                              <span
                                class={this.ns.be('caption', 'text')}
124
                                title={this.expBarModel?.title}
125
                              >
126
                                {this.expBarModel?.title}
127 128 129 130 131 132
                              </span>
                            ))}
                        </div>
                      </div>
                      <div class={this.ns.b('exp-bar-header-right')}>
                        <div class={this.ns.e('quick-search')}>
133
                          {c.complete && this.expBarModel?.enableSearch && (
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
                            <quick-search
                              value={c.query}
                              viewMode={c.modal.mode}
                              placeholder={c.model.placeholder}
                              onUpdate={(val: string) => {
                                c.query = val;
                              }}
                              onSearch={() => c.onSearch()}
                            ></quick-search>
                          )}
                        </div>
                        <div class={this.ns.e('toolbar')}>
                          {c.complete && c.model.toolbar && (
                            <view-toolbar
                              modelData={c.model.toolbar}
                              on-neuronInit={c.nerve.onNeuronInit(
                                c.model.toolbar.source.name,
                              )}
                              toolbarState={c.toolbarState}
                              viewMode={c.modal.mode}
                            ></view-toolbar>
                          )}
                        </div>
                      </div>
                    </div>
                    <div class={this.ns.b('exp-bar-content')}>
                      {inheritSlots.default && inheritSlots.default()}
                    </div>
                  </div>
                );
              },
            }}
          ></view-layout>
        </div>
        <div class={[this.ns.b('right')]}>
          {this.$scopedSlots.expView && this.$scopedSlots.expView({})}
        </div>
      </div>
    );
  },
});