searchMixins.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. isInterceptHtmlFn(text) {
  20. let name = this.$reg.interceptHtmlFn(text)
  21. return name
  22. },
  23. handeleCeptText(content, key, res) {
  24. if (res == undefined) {
  25. res = []
  26. }
  27. key = key.toUpperCase()
  28. let keyLen = key.length
  29. let tmp = content.toUpperCase()
  30. if (tmp.length >= keyLen && keyLen > 0) {
  31. let index = -1
  32. index = tmp.indexOf(key)
  33. if (index != -1) {
  34. let n = content.substring(0, index)
  35. res.push({
  36. type: 2,
  37. text: n
  38. })
  39. let y = content.substring(index, index + keyLen)
  40. res.push({
  41. type: 1,
  42. text: y
  43. })
  44. content = content.substring(index + keyLen, content.length)
  45. this.handeleCeptText(content, key, res)
  46. } else {
  47. res.push({
  48. type: 2,
  49. text: content
  50. })
  51. }
  52. } else {
  53. res.push({
  54. type: 2,
  55. text: content
  56. })
  57. }
  58. return res
  59. },
  60. myReplace(content) {
  61. content = content.replace(' ', ' ')
  62. if (content.indexOf(' ') != -1) {
  63. return myReplace(content)
  64. }
  65. return content
  66. }
  67. }
  68. }
  69. export default searchMixins