tran-visited.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * 当前所有已查看页面匹配规则
  3. * @type {{project: string, ent: string, issued: string, content: string, buyer: string}}
  4. */
  5. const Rules = {
  6. content: 'article/content/*',
  7. issued: 'article/issued',
  8. ent: 'ent(_ser)?_portrait',
  9. buyer: 'client_portrayal',
  10. project: 'client_follow_detail'
  11. }
  12. /**
  13. * 旧数据模型转换处理,同时兼容新旧模型使用
  14. */
  15. class VisitedModelTransform {
  16. constructor (list = []) {
  17. this.list = list
  18. return this
  19. }
  20. checkPathRules (path) {
  21. let result = path
  22. for (const type in Rules) {
  23. if (new RegExp(Rules[type]).test(path)) {
  24. result = type
  25. break
  26. }
  27. }
  28. return result
  29. }
  30. transformItem (item) {
  31. return {
  32. id: item?.id || item?.search.replace(/(id|sid|entName)=/, ''),
  33. type: item?.type || this.checkPathRules(item?.path),
  34. path: item?.path,
  35. timestamp: item?.timestamp
  36. }
  37. }
  38. transform (list = this.list) {
  39. return list.map(this.transformItem.bind(this))
  40. }
  41. }
  42. export default VisitedModelTransform