Requirement: vUE page, obtain the parameters of the current page, if and set default values for some parameters

There was no backup of the original code, only screenshots, which were very inelegant and simple, and the complexity was red and then changed to orange

// Get the current page
export const getUrlParams = (routeQuery) = > {
  const {
    channel = this.$channel,
    agentCode = this.$agentCode,
    salorCode,
    agent,
    group,
    client = 'default',
    user = 'user',
  } = routeQuery

  let paramsJson = {
    channel,
    agentCode,
    client,
    user,
  }
  // Optional chain operator
  // paramsJson.salorCode=routeQuery? .salorCode;
  // console.log(paramsJson);
  if (channel == 'AA' || channel == 'BB') {
    if (salorCode) paramsJson.salorCode = salorCode
    console.log(paramsJson)
  } else if (channel == 'CC') {
    if (agent) paramsJson.agent = agent
    if (group) paramsJson.group = group
  }
  return paramsJson
}
Copy the code