App.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <div
  3. id="app"
  4. :style="{
  5. background: variables[`${style}-container-background`],
  6. '--background': variables[`${style}-top-bar-background`],
  7. '--menuColor': variables[`${style}-menu-color`],
  8. '--topColor': variables[`${style}-tab-color`],
  9. }"
  10. >
  11. <keep-alive :include="keepaliveIncludes">
  12. <router-view />
  13. </keep-alive>
  14. </div>
  15. </template>
  16. <script>
  17. import { mapGetters } from 'vuex'
  18. import { keepaliveIncludes } from '@/utils/handleRoutes.js'
  19. import { getMainByDefKey, getCode } from '@/api/appCenter.js'
  20. import variables from '@/styles/variables.scss'
  21. import _ from 'lodash'
  22. import * as dd from 'dingtalk-jsapi'
  23. export default {
  24. name: 'App',
  25. computed: {
  26. ...mapGetters({
  27. style: 'settings/style',
  28. themeColor: 'settings/themeColor',
  29. }),
  30. variables() {
  31. return variables
  32. },
  33. keepaliveIncludes() {
  34. return keepaliveIncludes
  35. },
  36. },
  37. data() {
  38. return {
  39. isDingIntent: true,
  40. }
  41. },
  42. created() {
  43. // 因为resize事件在整个项目中只能监听一次,所以这里通过全局广播发送这个事件
  44. window.onresize = _.debounce(() => {
  45. this.$root.$emit('resize')
  46. }, 300)
  47. String.prototype.getValue = function (parm) {
  48. var reg = new RegExp('(^|&)' + parm + '=([^&]*)(&|$)')
  49. var r = this.substr(this.indexOf('?') + 1).match(reg)
  50. if (r != null) return unescape(r[2])
  51. return null
  52. }
  53. var url = decodeURI(window.location.href)
  54. url = decodeURI(url)
  55. console.log(url)
  56. var corpId = url.getValue('corpId') //钉钉企业id
  57. var taskId = url.getValue('taskId') //任务id
  58. var instId = url.getValue('instId') //实例id
  59. var todoId = url.getValue('todoId') //实例id
  60. var messageId = url.getValue('messageId') //实例id
  61. var appId = url.getValue('appId') //应用id
  62. console.log('corpId======' + corpId)
  63. console.log('taskId======' + taskId)
  64. console.log('instId======' + instId)
  65. console.log('todoId======' + todoId)
  66. console.log('messageId======' + messageId)
  67. console.log('appId======' + appId)
  68. var dateEnti = {}
  69. if (taskId || todoId || messageId || appId) {
  70. dateEnti = {
  71. corpId: corpId,
  72. taskId: taskId,
  73. instId: instId,
  74. todoId: todoId,
  75. messageId: messageId,
  76. appId: appId,
  77. }
  78. var that = this
  79. dd.runtime.permission.requestAuthCode({
  80. corpId: corpId, // 企业id
  81. onSuccess: function (info) {
  82. console.log(info.code)
  83. that.getDingUserInfo(info.code, corpId, appId, dateEnti)
  84. },
  85. onFail: function (error) {},
  86. })
  87. } else {
  88. this.isDingIntent = false
  89. }
  90. },
  91. methods: {
  92. /**
  93. * 获取用户信息并且写入缓存
  94. * @param code
  95. * @param corpId
  96. * @param appId
  97. */
  98. getDingUserInfo(code, corpId, appId, dateEnti) {
  99. console.log(dateEnti)
  100. let url = `${window.context.auth}/sso/getDingUserByCode?code=${code}&corpId=${corpId}&appId=${appId}`
  101. let _this = this
  102. this.$http.get(url).then((resp) => {
  103. console.log(resp)
  104. let code = resp.code
  105. if (code == '200') {
  106. let value = resp.value
  107. this.$store.dispatch('user/getDingUserByCodeFun', value)
  108. if (dateEnti.taskId) {
  109. this.$router.push({
  110. path: '/matter/approvalForm',
  111. query: {
  112. instId: dateEnti.instId,
  113. taskId: dateEnti.taskId,
  114. isGetApprovalBtn: true,
  115. type: 'fromTodoList',
  116. // key:'onlyOneTask'
  117. },
  118. })
  119. }
  120. if (dateEnti.appId) {
  121. this.getAppInfo(appId)
  122. }
  123. if (dateEnti.todoId) {
  124. this.getTodoDetailById(dateEnti)
  125. }
  126. if (dateEnti.messageId) {
  127. this.messageReceiver(dateEnti)
  128. }
  129. }
  130. })
  131. },
  132. /**
  133. * 获取待办详细信息
  134. * @param code
  135. * @param corpId
  136. * @param appId
  137. */
  138. getTodoDetailById(dateEnti) {
  139. console.log(dateEnti)
  140. let url = `${window.context.bpmRunTime}/runtime/todo/v1/getDetailById?id=${dateEnti.todoId}`
  141. let _this = this
  142. this.$http.get(url).then((resp) => {
  143. console.log(resp)
  144. let code1 = resp.code
  145. if (code1 == '200') {
  146. let value = resp.value
  147. _this.getCodeFun(value, '0')
  148. }
  149. })
  150. },
  151. getCodeFun(resp, type) {
  152. getCode().then((res) => {
  153. if (res.code === 200) {
  154. let code = res.value
  155. if (type == '1') {
  156. var sourceClient = 'PC'
  157. var param = resp.messageParams
  158. var preFlag = '?'
  159. var url = resp.ownerSourceCurAppCallback
  160. if (url.indexOf('?') > 0) {
  161. preFlag = '&'
  162. }
  163. var resultUrl =
  164. url +
  165. preFlag +
  166. 'code=' +
  167. code +
  168. '&sourceClient=' +
  169. sourceClient +
  170. '&pageData=' +
  171. encodeURIComponent(param)
  172. window.location.href = resultUrl
  173. }
  174. if (type == '0') {
  175. var sourceClient = 'PC'
  176. var param = resp.messageParams
  177. var preFlag = '?'
  178. var url = resp.ownerSourceCurAppCallback
  179. if (url.indexOf('?') > 0) {
  180. preFlag = '&'
  181. }
  182. var resultUrl =
  183. url +
  184. preFlag +
  185. 'code=' +
  186. code +
  187. '&sourceClient=' +
  188. sourceClient +
  189. '&pageData=' +
  190. encodeURIComponent(param)
  191. window.location.href = resultUrl
  192. }
  193. }
  194. })
  195. },
  196. /**
  197. * 获取待办详细信息
  198. * @param code
  199. * @param corpId
  200. * @param appId
  201. */
  202. messageReceiver(dateEnti) {
  203. console.log(dateEnti)
  204. let url = `${window.context.portal}/innermsg/messageReceiver/v1/get?id=${dateEnti.messageId}`
  205. let _this = this
  206. this.$http.get(url).then((resp) => {
  207. console.log(resp)
  208. let messageSourceType = resp.messageSourceType
  209. if (messageSourceType == '1') {
  210. window.location.href = resp.messageUrl
  211. } else if (
  212. messageSourceType == '3' ||
  213. messageSourceType == '4' ||
  214. messageSourceType == '5' ||
  215. messageSourceType == '6'
  216. ) {
  217. _this.getCodeFun(resp, '1')
  218. }
  219. })
  220. },
  221. /**
  222. * 根据appid获取app数据
  223. * @param appId
  224. */
  225. getAppInfo(appId) {
  226. let url = `${window.context.portal}/portal/sysApp/v1/getDetail?id=${appId}`
  227. let _this = this
  228. this.$http.get(url).then((resp) => {
  229. console.log(resp)
  230. let code = resp.status
  231. if (code == '200') {
  232. let value = resp.data
  233. _this.clickGrid(value)
  234. }
  235. })
  236. },
  237. async startApp(app) {
  238. //1常规应用 2数据报表 3自定义视图 4图表 6表单 7模块 8启动流程
  239. ///appContent/:type/:id/:otherId/:appName
  240. let url = ''
  241. let prefix = window.context.front
  242. if (app.type == 4) {
  243. let content = JSON.parse(app.content)
  244. url = `/appContent?type=${app.type}&id=${content.id}&appName=${app.name}`
  245. } else if (app.type === 2) {
  246. let content = JSON.parse(app.content)
  247. url = `/appContent?type=${app.type}&id=${content.alias}&appName=${app.name}`
  248. } else if (app.type === 3) {
  249. let content = JSON.parse(app.content)
  250. url = `/appContent?type=${app.type}&id=${content.id}&appName=${app.name}`
  251. } else if (app.type === 1) {
  252. url = `/appContent?type=${app.type}&id=${app.id}&appName=${app.name}`
  253. } else if (app.type === 6) {
  254. let content = JSON.parse(app.content)
  255. url = `/appContent?type=${app.type}&id=${content.id}&appName=${app.name}`
  256. } else if (app.type === 7) {
  257. let content = JSON.parse(app.content)
  258. url = `/appContent?type=${app.type}&id=${content.id}&appName=${app.name}`
  259. } else if (app.type === 8) {
  260. let content = JSON.parse(app.content)
  261. let resp = {}
  262. if (content.key) {
  263. resp = await getMainByDefKey(content.key)
  264. url = `/matter/startProcess?defId=${resp.id}&name=${content.name}`
  265. } else {
  266. url = `/matter/startProcess?defId=${content.id}&name=${content.name}`
  267. }
  268. } else if (app.type === 9) {
  269. let content = JSON.parse(app.content)
  270. url = `/appContent?type=${app.type}&id=${content.id}&appName=${app.name}&alias=${content.alias}`
  271. } else if (app.type === 5) {
  272. url = app.content
  273. if (app.localAuthCode === 1) {
  274. this.getCode(url)
  275. } else {
  276. window.open(url, '_blank')
  277. }
  278. return
  279. }
  280. if (url) {
  281. this.$router.push({ path: url })
  282. }
  283. },
  284. },
  285. }
  286. </script>
  287. <style lang="scss">
  288. #app {
  289. height: 100%;
  290. }
  291. .el-button--primary {
  292. background-color: #2563eb;
  293. border-color: #2563eb;
  294. }
  295. </style>