App.vue 9.7 KB

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