translationOpenData.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="translation">
  3. <!-- 文本 -->
  4. <template v-if="renderType[configuration.renderIndex] === 'text'">
  5. <span v-if="corporateWeChat && !noRender.includes(translationValue)">
  6. <ww-open-data :type='configuration.openType' :openid='translationValue'></ww-open-data>
  7. </span>
  8. <span v-else-if="dingdingPlatform && !noRender.includes(translationValue)">
  9. <dt-open-data :open-type='dingdingOpenType[configuration.openType]' :open-id='translationValue'></dt-open-data>
  10. </span>
  11. <span v-else>{{ translationValue }}</span>
  12. </template>
  13. <!-- 数组 -->
  14. <template v-if="renderType[configuration.renderIndex] === 'array'">
  15. </template>
  16. <!-- 对象 -->
  17. <template v-if="renderType[configuration.renderIndex] === 'object'">
  18. </template>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. name: '',
  24. components: {},
  25. props: {
  26. configurationItems: {
  27. type: Object,
  28. default: () => {
  29. return {
  30. openType: 'userName',
  31. openId: '',
  32. renderIndex: 0, // 0: 纯文本,1:数组,2:显示工号
  33. }
  34. }
  35. }
  36. },
  37. data() {
  38. return {
  39. user: JSON.parse(sessionStorage.getItem("user")),
  40. renderType: ['text', 'array', 'object'],
  41. corporateWeChat: false, // 企业微信转译
  42. dingdingPlatform: false, // 钉钉转译
  43. translationValue: '', // 文本转译值
  44. translationValArray: [], // 数组转译值
  45. translationValObject: {}, // 对象转译值
  46. configuration: {
  47. openType: 'userName',
  48. openId: '',
  49. renderIndex: 0,
  50. }, // 配置对象
  51. noRender: ['全部人员', '未分配'],
  52. dingdingOpenType: {
  53. userName: 'userName',
  54. departmentName: 'deptName',
  55. }
  56. }
  57. },
  58. computed: {},
  59. watch: {
  60. configurationItems: {
  61. handler(newVal, oldVal) {
  62. this.assignmentValue(newVal)
  63. },
  64. }
  65. },
  66. created() { },
  67. mounted() {
  68. this.dealWith()
  69. },
  70. methods: {
  71. dealWith() {
  72. // console.log(this.user)
  73. const { userNameNeedTranslate, dingdingUserid } = this.user
  74. if (userNameNeedTranslate) {
  75. this.corporateWeChat = true
  76. if (dingdingUserid) {
  77. this.dingdingPlatform = true
  78. this.corporateWeChat = false
  79. } else {
  80. this.dingdingPlatform = false
  81. }
  82. } else {
  83. this.corporateWeChat = false
  84. this.dingdingPlatform = false
  85. }
  86. // console.log(this.corporateWeChat, this.dingdingPlatform, this.configurationItems)
  87. // console.log(this.corporateWeChat, '<=== 企业微信转译')
  88. // console.log(this.dingdingPlatform, '<=== 钉钉转译')
  89. this.assignmentValue(this.configurationItems)
  90. },
  91. assignmentValue(value) {
  92. const { openType, openId, renderIndex = 0 } = value
  93. this.configuration = { openType, openId, renderIndex }
  94. const type = this.renderType[renderIndex]
  95. switch (type) {
  96. case 'text':
  97. this.translationValue = openId
  98. break;
  99. case 'array':
  100. this.translationValArray = openId.split(',')
  101. break;
  102. case 'object':
  103. this.translationValObject = openId
  104. break;
  105. default:
  106. break;
  107. }
  108. // console.log(this.translationValue, '<=== 转译文本')
  109. if (this.user.dingdingUserid) {
  110. this.viewConfiguration()
  111. }
  112. },
  113. viewConfiguration() {
  114. setTimeout(() => {
  115. window.DTOpenData.update(document.querySelectorAll('dt-open-data'));
  116. }, 100);
  117. }
  118. },
  119. }
  120. </script>
  121. <style scoped lang='scss'>
  122. .translation {
  123. width: auto;
  124. display: inline-block;
  125. }
  126. </style>