utils.jsx 8.59 KB
Newer Older
张烨's avatar
张烨 committed
1 2
import { ITEM_TYPE } from '@/components/BaseForm';

张烨's avatar
张烨 committed
3 4 5 6
export const webMode = {
  single: 'single',
  integration: 'integration',
};
张烨's avatar
张烨 committed
7 8 9 10 11 12
const typeContent = hasIntegerate => {
  if (hasIntegerate) {
    return [];
  }
  return [
    {
张烨's avatar
张烨 committed
13
      value: webMode.integration,
张烨's avatar
张烨 committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
      children: '集成网站',
    },
  ];
};

export const integrateStyleData = {
  platform: '工作台',
  webgis: 'WEBGIS',
  ios: 'IOS',
  catalog: 'Catalog',
  virtualcity: 'VirtualCity',
};
export const singleStyleData = {
  platform: '工作台',
  webgis: 'WEBGIS',
};
export const menuStyle = {
31 32 33 34 35 36
  'banner-left': '经典',
  // banner: '标题栏',
  // 'banner-big': '标题栏-大',
  // table: '左侧',
  // dock: '底部',
  // 'banner-left-noShrink': '标题栏-左-不收',
张烨's avatar
张烨 committed
37
};
38 39 40
// 消息标记
export const markingLabel = {
  All: '多人',
邓超's avatar
邓超 committed
41
  One: '单人',
42 43 44 45 46 47
};
// 语音播报
export const voiceLabel = {
  true: '开',
  false: '关',
};
张烨's avatar
张烨 committed
48 49 50 51 52
export const MDILabel = {
  MDI: '多标签模式',
  SDI: '单标签模式',
};
export const notificationTypes = {
53
  // notify: '轮询通知',
张烨's avatar
张烨 committed
54 55 56
  MQTT: 'MQTT消息',
};

张烨's avatar
张烨 committed
57 58 59
const isIntegerate = (mode, hasIntegerate) => {
  if (typeof mode !== 'undefined') {
    return mode === 'single';
张烨's avatar
张烨 committed
60 61 62 63
  }
  return hasIntegerate;
};

张烨's avatar
张烨 committed
64
export const defaultWebConfigObj = {
65 66
  title: '',
  subtitle: '',
张烨's avatar
张烨 committed
67
  mode: webMode.single,
68 69 70 71 72
  shortcutIcon: '',
  logo: '',
  client: '',
  bannerLogo: '',
  homePage: '',
张烨's avatar
张烨 committed
73 74
  menu: 'banner-left',
  mdi: 'MDI',
75 76 77 78 79 80
  theme: '',
  style: '',
  hideMap: false,
  waterMark: true,
  mapPlan: '',
  qrcode: '',
张烨's avatar
张烨 committed
81
  loginTemplate: 'Default.html',
82
  productType: '',
83
  alarmWays: notificationTypes.MQTT,
邓超's avatar
邓超 committed
84
  messageMarking: 'All',
85
  messageVoice: true,
张烨's avatar
张烨 committed
86
};
张烨's avatar
张烨 committed
87

张烨's avatar
张烨 committed
88 89 90 91 92 93 94 95 96
export const getDefaultGetWebconfig = ({
  initialValues = {},
  hasIntegerate,
  webThemes,
  onGetThemes,
  loginPages,
  onGetLoginPages,
  mapConfigs,
  onGetMapConfig,
Maofei94's avatar
Maofei94 committed
97 98
  products,
  onGetProduct,
张烨's avatar
张烨 committed
99
  isEdit,
100
  productList,
张烨's avatar
张烨 committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
}) => {
  const config = {
    title: {
      label: '标题',
      formType: ITEM_TYPE.INPUT,
      allowClear: true,
      placeholder: '请输入标题',
      rules: [
        {
          required: true,
          message: '标题为必填项',
        },
      ],
    },
    subtitle: {
      label: '副标题',
      formType: ITEM_TYPE.INPUT,
      allowClear: true,
    },
张烨's avatar
张烨 committed
120
    mode: {
张烨's avatar
张烨 committed
121 122
      label: '网站类型',
      formType: ITEM_TYPE.SINGLE_RADIO,
张烨's avatar
张烨 committed
123
      initialValue: webMode.single,
张烨's avatar
张烨 committed
124
      disabled: isEdit,
张烨's avatar
张烨 committed
125 126
      options: [
        {
张烨's avatar
张烨 committed
127
          value: webMode.single,
张烨's avatar
张烨 committed
128 129
          children: '一般网站',
        },
张烨's avatar
张烨 committed
130
      ], // .concat(typeContent(hasIntegerate)),
张烨's avatar
张烨 committed
131 132 133 134
    },
    shortcutIcon: {
      label: '系统icon',
      formType: ITEM_TYPE.IMGSHOP,
Maofei94's avatar
Maofei94 committed
135
      picType: 'icon',
张烨's avatar
张烨 committed
136 137 138 139 140 141 142 143 144 145
      rules: [
        {
          required: true,
          message: '请选择图标icon',
        },
      ],
    },
    logo: {
      label: '登录logo',
      formType: ITEM_TYPE.IMGSHOP,
Maofei94's avatar
Maofei94 committed
146
      picType: 'logo',
张烨's avatar
张烨 committed
147 148 149 150 151 152 153
      rules: [
        {
          required: true,
          message: '请选择登录logo',
        },
      ],
    },
张烨's avatar
张烨 committed
154
    bannerLogo: {
张烨's avatar
张烨 committed
155 156
      label: '标题logo',
      formType: ITEM_TYPE.IMGSHOP,
Maofei94's avatar
Maofei94 committed
157
      picType: 'logo',
张烨's avatar
张烨 committed
158 159 160 161 162 163 164 165 166 167
      rules: [
        {
          required: true,
          message: '请选择标题logo',
        },
      ],
    },
    client: {
      label: '虚拟目录',
      formType: ITEM_TYPE.INPUT,
张烨's avatar
张烨 committed
168
      disabled: isEdit,
张烨's avatar
张烨 committed
169 170 171 172 173 174 175 176 177
      allowClear: true,
      size: 'small',
      rules: [
        {
          required: true,
          message: '虚拟目录不能为空',
        },
      ],
    },
178 179 180 181 182
    productType: {
      label: '主页产品类型',
      formType: ITEM_TYPE.SELECT,
      placeholder: '请选择产品类型',
      options: products.map(t => ({
183 184
        value: t.PackageName,
        key: t.PackageName,
185 186 187 188 189 190 191 192 193 194 195 196 197
        children: t.ProductName,
      })),
      onDropdownVisibleChange: onGetProduct,
      showSearch: false,
      filterOption: (input, option) =>
        option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0,
      rules: [
        {
          required: false,
          message: '产品类型必填',
        },
      ],
    },
张烨's avatar
张烨 committed
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
    homePage: {
      label: '主页',
      formType: ITEM_TYPE.INPUT,
      allowClear: true,
    },
    loginTemplate: {
      label: '登录模板',
      formType: ITEM_TYPE.SELECT,
      placeholder: '请选择登录模板',
      options: loginPages.map(t => ({
        value: t.value,
        children: t.text,
        key: t.value,
      })),
      onDropdownVisibleChange: onGetLoginPages,
      showSearch: true,
      filterOption: (input, option) =>
        option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0,
      rules: [
        {
          required: true,
          message: '登录模板必填',
        },
      ],
    },
223

Maofei94's avatar
Maofei94 committed
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
    // theme: {
    //   label: '系统皮肤',
    //   formType: ITEM_TYPE.SELECT,
    //   initialValue: '',
    //   showSearch: true,
    //   filterOption: (input, option) =>
    //     option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0,
    //   options:
    //     webThemes.map(t => ({
    //       value: t.value,
    //       children: t.text,
    //       key: t.value,
    //     })) || [],
    //   onDropdownVisibleChange: onGetThemes,
    // },
    // style: {
    //   label: '系统风格',
    //   formType: ITEM_TYPE.SELECT,
    //   initialValue: '',
    //   options: Object.keys(
    //     isIntegerate(initialValues.mode, hasIntegerate)
    //       ? integrateStyleData
    //       : singleStyleData,
    //   ).map(k => ({
    //     value: k,
    //     key: k,
    //     children: integrateStyleData[k] || singleStyleData[k],
    //   })),
    // },
张烨's avatar
张烨 committed
253 254 255 256 257 258 259 260 261
    menu: {
      label: '菜单类型',
      formType: ITEM_TYPE.SINGLE_RADIO,
      options: Object.keys(menuStyle).map(k => ({
        value: k,
        key: k,
        children: menuStyle[k],
      })),
    },
Maofei94's avatar
Maofei94 committed
262 263 264 265 266 267 268 269 270
    // mdi: {
    //   label: '功能标签',
    //   formType: ITEM_TYPE.SINGLE_RADIO,
    //   options: Object.keys(MDILabel).map(k => ({
    //     value: k,
    //     key: k,
    //     children: MDILabel[k],
    //   })),
    // },
张烨's avatar
张烨 committed
271 272 273 274 275
    qrcode: {
      label: '二维码地址',
      formType: ITEM_TYPE.INPUT,
      allowClear: true,
    },
276 277 278 279
    messageMarking: {
      label: '消息标记',
      formType: ITEM_TYPE.SINGLE_RADIO,
      options: Object.keys(markingLabel).map(k => ({
张烨's avatar
张烨 committed
280 281
        value: k,
        key: k,
282
        children: markingLabel[k],
张烨's avatar
张烨 committed
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
    messageVoice: {
      label: '语音播报',
      formType: ITEM_TYPE.SINGLE_RADIO,
      optionType: 'button',
      options: [
        {
          value: true,
          key: '1',
          children: '开',
        },
        {
          value: false,
          key: '2',
          children: '关',
        },
      ],
    },
    // alarmWays: {
    //   label: '通知方式',
    //   formType: ITEM_TYPE.CHECK_BOX,
    //   options: Object.keys(notificationTypes).map(k => ({
    //     value: k,
    //     key: k,
    //     children: notificationTypes[k],
    //   })),
    // },
Maofei94's avatar
Maofei94 committed
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
    // mapPlan: {
    //   label: '地图方案',
    //   formType: ITEM_TYPE.SELECT,
    //   options: mapConfigs.map(m => ({
    //     value: m.value,
    //     children: m.text,
    //     key: m.value,
    //   })),
    //   onDropdownVisibleChange: onGetMapConfig,
    // },
    // hideMap: {
    //   label: '按需加载地图',
    //   formType: ITEM_TYPE.SINGLE_RADIO,
    //   optionType: 'button',
    //   options: [
    //     {
    //       value: true,
    //       key: '1',
    //       children: '是',
    //     },
    //     {
    //       value: false,
    //       key: '2',
    //       children: '否',
    //     },
    //   ],
    // },
    // waterMark: {
    //   label: '地图水印',
    //   formType: ITEM_TYPE.SINGLE_RADIO,
    //   options: [
    //     {
    //       value: true,
    //       key: '1',
    //       children: '显示',
    //     },
    //     {
    //       value: false,
    //       key: '2',
    //       children: '不显示',
    //     },
    //   ],
    // },
张烨's avatar
张烨 committed
354
  };
张烨's avatar
张烨 committed
355 356
  if (initialValues) {
    Object.keys(config).forEach(k => {
357
      config[k].initialValue = typeof initialValues[k] !== 'undefined' ? initialValues[k] : '';
Maofei94's avatar
Maofei94 committed
358 359 360
      // if (k === 'alarmWays') {
      //   config[k].initialValue = config[k].initialValue.split(',');
      // }
张烨's avatar
张烨 committed
361 362 363 364 365 366 367 368 369 370 371 372 373
      // if (k === 'mode' && initialValues.mode) {
      //   config[k].options = [
      //     {
      //       value: webMode.single,
      //       children: '一般网站',
      //     },
      //     // {
      //     //   value: webMode.integration,
      //     //   children: '集成网站',
      //     // },
      //   ];
      //   config[k].initialValue = webMode.single; // initialValues.mode;
      // }
张烨's avatar
张烨 committed
374 375
    });
  }
张烨's avatar
张烨 committed
376 377
  return config;
};