{"size": 1084, "ext": "js", "max_stars_repo_path": "src/store/mutations/model.js", "max_stars_repo_name": "epage-team/epage-core", "max_stars_repo_stars_event_min_datetime": "2020-07-08T17:52:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-05T05:38:40.000Z", "max_issues_repo_path": "src/store/mutations/model.js", "max_issues_repo_name": "epage-team/epage-core", "max_issues_repo_issues_event_min_datetime": "2020-12-15T07:10:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-15T07:10:16.000Z", "max_forks_repo_path": "src/store/mutations/model.js", "max_forks_repo_name": "epage-team/epage-core", "max_forks_repo_forks_event_min_datetime": "2020-09-22T07:58:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T05:40:57.000Z"}
{"max_stars_count": 23, "max_issues_count": 1, "max_forks_count": 13, "avg_line_length": 23.5652173913, "max_line_length": 81, "alphanum_fraction": 0.6208487085}
import types from '../types'
import {
  isFunction,
  isString,
  checkValueType,
  convertNameModelToKeyModel
} from '../../helper'

export default {
  // 设置表单model，即用户填写的表单数据
  [types.$MODEL_SET] (state, { model, useName }) {
    const { flatSchemas } = state
    const { flatWidgets } = this.getters
    const _model = {}
    let keyModel = model // 以schema.key为key组成的model对象

    if (useName) {
      keyModel = convertNameModelToKeyModel(model, flatSchemas)
    }
    const conbinedModel = Object.assign({}, state.model, keyModel)

    for (const i in conbinedModel) {
      const schema = flatSchemas[i]

      if (!schema) {
        continue
      }

      const Widget = flatWidgets[schema.widget]

      if (!Widget || !isFunction(Widget.Schema)) {
        continue
      }

      if (schema.type === 'json' && !isString(conbinedModel[i])) {
        conbinedModel[i] = JSON.stringify(conbinedModel[i])
      }

      if (checkValueType(conbinedModel[i], Widget.Schema.type, schema.dynamic)) {
        _model[i] = conbinedModel[i]
      }
    }
    state.model = _model
  }
}
