searchMixins.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. console.log('res',res)
  59. return res
  60. },
  61. myReplace(content) {
  62. content = content.replace(' ', ' ')
  63. if (content.indexOf(' ') != -1) {
  64. return myReplace(content)
  65. }
  66. return content
  67. }
  68. }
  69. }
  70. export default searchMixins