translationOpenData.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.dingdingPlatform = false
  79. this.corporateWeChat = false
  80. } else {
  81. this.dingdingPlatform = false
  82. }
  83. } else {
  84. this.corporateWeChat = false
  85. this.dingdingPlatform = false
  86. }
  87. // console.log(this.corporateWeChat, this.dingdingPlatform, this.configurationItems)
  88. // console.log(this.corporateWeChat, '<=== 企业微信转译')
  89. // console.log(this.dingdingPlatform, '<=== 钉钉转译')
  90. this.assignmentValue(this.configurationItems)
  91. },
  92. assignmentValue(value) {
  93. const { openType, openId, renderIndex = 0 } = value
  94. this.configuration = { openType, openId, renderIndex }
  95. const type = this.renderType[renderIndex]
  96. switch (type) {
  97. case 'text':
  98. this.translationValue = openId
  99. break;
  100. case 'array':
  101. this.translationValArray = openId.split(',')
  102. break;
  103. case 'object':
  104. this.translationValObject = openId
  105. break;
  106. default:
  107. break;
  108. }
  109. // console.log(this.translationValue, '<=== 转译文本')
  110. // if (this.user.dingdingUserid) {
  111. // this.viewConfiguration()
  112. // }
  113. },
  114. viewConfiguration() {
  115. setTimeout(() => {
  116. window.DTOpenData.update(document.querySelectorAll('dt-open-data'));
  117. }, 100);
  118. }
  119. },
  120. }
  121. </script>
  122. <style scoped lang='scss'>
  123. .translation {
  124. width: auto;
  125. display: inline-block;
  126. }
  127. </style>