index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import $store from '@/sheep/store';
  2. import { staticUrl } from '@/sheep/config';
  3. import { append_thumbnail_params } from './reseize';
  4. // 添加cdn域名前缀
  5. export const _cdn = (url = '', cdnurl = '') => {
  6. if (!url) return '';
  7. if (url.indexOf('http') === 0) {
  8. return url;
  9. }
  10. if (cdnurl === '') {
  11. cdnurl = $store('app').info.cdnurl;
  12. }
  13. return cdnurl + url;
  14. };
  15. // 对象存储自动剪裁缩略图
  16. export const _thumb = (url = '', params) => {
  17. url = _cdn(url);
  18. return append_thumbnail_params(url, params);
  19. }
  20. // 静态资源地址
  21. export const _static = (url = '', staticurl = '') => {
  22. if (staticurl === '') {
  23. staticurl = staticUrl;
  24. }
  25. if (staticurl !== 'local') {
  26. url = _cdn(url, staticurl);
  27. }
  28. return url;
  29. }
  30. // css背景图片地址
  31. export const _css = (url = '', staticurl = '') => {
  32. if (staticurl === '') {
  33. staticurl = staticUrl;
  34. }
  35. if (staticurl !== 'local') {
  36. url = _cdn(url, staticurl);
  37. }
  38. // #ifdef APP-PLUS
  39. if (staticurl === 'local') {
  40. url = plus.io.convertLocalFileSystemURL(url);
  41. }
  42. // #endif
  43. return `url(${url})`;
  44. }
  45. export default {
  46. cdn: _cdn,
  47. static: _static,
  48. css: _css,
  49. thumb: _thumb
  50. }