common.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import CryptoJS from 'crypto-js'
  2. import jump from '@/utils/jump'
  3. export default {
  4. back(obj = {}) {
  5. let { delta = 1, ...config } = obj
  6. uni.navigateBack({ delta, ...config })
  7. },
  8. // AES 加密
  9. Encryption(word) {
  10. let words = CryptoJS.enc.Utf8.parse(word)
  11. let key = CryptoJS.enc.Utf8.parse('DBFD3mmyG68BpdOM')
  12. let iv = CryptoJS.enc.Utf8.parse('yj22318211233hip')
  13. let encrypted = CryptoJS.AES.encrypt(words, key, { iv: iv }).toString()
  14. return decodeURIComponent(encrypted)
  15. },
  16. // AES 解密
  17. Decryption(word) {
  18. let key = CryptoJS.enc.Utf8.parse('DBFD3mmyG68BpdOM')
  19. let iv = CryptoJS.enc.Utf8.parse('yj22318211233hip')
  20. let decrypted = CryptoJS.AES.decrypt(word, key, { iv: iv }).toString(CryptoJS.enc.Utf8)
  21. return decodeURIComponent(decrypted)
  22. },
  23. toast(title, icon = 'none', duration = 1500) {
  24. uni.showToast({
  25. title: title,
  26. icon: icon,
  27. duration: duration
  28. })
  29. },
  30. // 复制
  31. copy(value, title = '已复制') {
  32. uni.setClipboardData({
  33. data: value, //要被复制的内容
  34. success: () => {
  35. //复制成功的回调函数
  36. uni.showToast({
  37. //提示
  38. title: title,
  39. icon: 'none'
  40. })
  41. }
  42. })
  43. },
  44. toLogin(type = 'navigateTo') {
  45. jump({ url: '/pages/login/login', animationType: 'slide-in-bottom' }, {}, type)
  46. }
  47. }