searchMixins.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // 统计数据
  2. // 统计类型 1:首页banner;2:直播模块;3:最新活动;4:热门文章;5:新品橱窗;6:活动列表
  3. import Vue from 'vue'
  4. const searchMixins = {
  5. computed: {
  6. },
  7. methods: {
  8. sliceStr(str, len) {
  9. var len = len || 8
  10. if (str != null) {
  11. if (str.length > len) {
  12. return str.substring(0, len) + '...'
  13. } else {
  14. return str
  15. }
  16. }
  17. return ''
  18. },
  19. highLight(content, key, res) {
  20. if (res == undefined) {
  21. res = []
  22. }
  23. key = key.toUpperCase()
  24. let keyLen = key.length
  25. let tmp = content.toUpperCase()
  26. if (tmp.length >= keyLen && keyLen > 0) {
  27. let index = -1
  28. index = tmp.indexOf(key)
  29. if (index != -1) {
  30. let n = content.substring(0, index)
  31. res.push({
  32. type: 2,
  33. text: n
  34. })
  35. let y = content.substring(index, index + keyLen)
  36. res.push({
  37. type: 1,
  38. text: y
  39. })
  40. content = content.substring(index + keyLen, content.length)
  41. this.highLight(content, key, res)
  42. } else {
  43. res.push({
  44. type: 2,
  45. text: content
  46. })
  47. }
  48. } else {
  49. res.push({
  50. type: 2,
  51. text: content
  52. })
  53. }
  54. return res
  55. },
  56. myReplace(content) {
  57. content = content.replace(' ', ' ')
  58. if (content.indexOf(' ') != -1) {
  59. return myReplace(content)
  60. }
  61. return content
  62. }
  63. }
  64. }
  65. export default searchMixins