index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import i18n from '@/util/lang/lang'
  2. let dom = null
  3. async function asyncConstructor (Vue, comp) {
  4. if (!comp) {
  5. let component = await import('./index.vue')
  6. comp = Vue.extend(component.default)
  7. return comp
  8. }
  9. return comp
  10. }
  11. let Avatar = {}
  12. Avatar.install = function (Vue, store) {
  13. let instance
  14. Vue.prototype.$editUserAvatar = async (imageUrl = '') => {
  15. let Constructor = await asyncConstructor(Vue, dom)
  16. if (instance) {
  17. instance.visible = true
  18. instance.imageUrl = imageUrl
  19. instance.isMe = true
  20. } else {
  21. instance = new Constructor({
  22. el: document.createElement('div'),
  23. computed: {
  24. $store () {
  25. return store
  26. }
  27. },
  28. i18n,
  29. data () {
  30. return {
  31. visible: true,
  32. imageUrl,
  33. isMe: true
  34. }
  35. }
  36. })
  37. document.body.appendChild(instance.$el)
  38. }
  39. }
  40. Vue.prototype.$editGroupAvatar = async (imageUrl = '') => {
  41. let Constructor = await asyncConstructor(Vue, dom)
  42. if (instance) {
  43. instance.visible = true
  44. instance.imageUrl = imageUrl
  45. instance.isMe = false
  46. } else {
  47. instance = new Constructor({
  48. el: document.createElement('div'),
  49. computed: {
  50. $store () {
  51. return store
  52. }
  53. },
  54. i18n,
  55. data () {
  56. return {
  57. visible: true,
  58. imageUrl,
  59. isMe: false
  60. }
  61. }
  62. })
  63. document.body.appendChild(instance.$el)
  64. }
  65. }
  66. }
  67. export default Avatar