index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div class="layoutsMain">
  3. <Loading :loading="!pageLoading" />
  4. <div v-show="pageLoading">
  5. <div v-show="vshowList">
  6. <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
  7. <van-list v-model="loading" :finished="finished" @load="onLoad">
  8. <div v-for="item in list" :key="item.id" :title="item" class="item-box" @click="goView(item)">
  9. <div class="remind">
  10. <van-image :src="require('../../../static/images/icon_pdf.png')" />
  11. </div>
  12. <div class="detail">
  13. <div class="notice-header">
  14. <div class="notice-title">{{ item.name }}</div>
  15. </div>
  16. <div class="notice-content">
  17. {{ item.fileSize}}
  18. </div>
  19. </div>
  20. <div class="line"></div>
  21. <div class="arrow">
  22. <van-image class="imgview" :src="require('../../../static/images/icon_view.png')" />
  23. 查看
  24. </div>
  25. </div>
  26. </van-list>
  27. </van-pull-refresh>
  28. <van-empty v-if="list.length == 0" description="暂无数据" />
  29. </div>
  30. <div v-show="!vshowList" class="jurisdiction">
  31. <van-image :src="require('../../../static/images/icon_jurisdiction.png')" />
  32. <div>{{nomessage}}</div>
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. import Loading from '@/components/Loading';
  39. import * as dd from 'dingtalk-jsapi';
  40. export default {
  41. data() {
  42. return {
  43. list: [],
  44. pageLoading: false,
  45. vshowList: true,
  46. loading: false,
  47. finished: false,
  48. refreshing: false,
  49. nomessage: '暂无访问权限',
  50. watermark: 'HSAY',
  51. pageInfo: {
  52. pageIndex: 1,
  53. pageSize: 10
  54. },
  55. }
  56. },
  57. components: {
  58. Loading
  59. },
  60. created() {
  61. this.getAuthconfig();
  62. },
  63. methods: {
  64. goView(item) {
  65. this.$router.push({
  66. name: 'page',
  67. query: {
  68. id: item.id,
  69. title: item.name
  70. }
  71. })
  72. },
  73. onLoad() {
  74. let self = this
  75. //判断获取到分类id
  76. if (this.$route.query.typeId) {
  77. if (this.refreshing) {
  78. this.list = []
  79. this.refreshing = false
  80. this.pageInfo.pageIndex = 1
  81. }
  82. const params = {
  83. typeId: this.$route.query.typeId || '',
  84. page: this.pageInfo.pageIndex,
  85. pageSize: this.pageInfo.pageSize
  86. }
  87. this.$api.user.getDocList(params).then((response) => {
  88. self.pageLoading = true;
  89. const res = response.data;
  90. if (res.code == 0 && res.data.list) {
  91. if (res.data.list.length == 1 && this.pageInfo.pageIndex == 1) {
  92. self.loading = false
  93. self.finished = true
  94. let item = res.data.list[0];
  95. this.$router.replace({
  96. name: 'page',
  97. query: {
  98. id: item.id,
  99. title: item.name
  100. }
  101. })
  102. } else {
  103. self.list.push(...res.data.list)
  104. self.watermark = res.data.watermark;
  105. self.pageInfo.pageIndex += 1
  106. self.loading = false
  107. if (self.list.length >= res.data.totalCount) {
  108. self.finished = true
  109. }
  110. this.ChangePageTitle(self.list[0].typeName)
  111. }
  112. } else if (res.code == 1000) { //没有查看权限
  113. this.vshowList = false;
  114. this.nomessage = res.message
  115. }
  116. }).catch(err => {
  117. console.log(err);
  118. self.pageLoading = true;
  119. });
  120. } else if (this.$route.query.docId) { //直接获取到分件Id 打开文件, title: '阅读'
  121. this.$api.user.getDetail(this.$route.query.docId, localStorage.userId || '').then((response) => {
  122. self.pageLoading = true;
  123. const res = response.data.data;
  124. if (res.code == 0 && res.data) {
  125. let path = res.data.path || ''
  126. this.$router.replace({
  127. name: 'page',
  128. query: {
  129. path: path,
  130. title: res.data.fileName
  131. }
  132. })
  133. } else if (res.code == 1000) { //没有查看权限
  134. this.vshowList = false;
  135. this.nomessage = res.message
  136. }
  137. }).catch(err => {
  138. console.log(err);
  139. self.pageLoading = true;
  140. });
  141. }
  142. },
  143. onRefresh() {
  144. // 清空列表数据
  145. this.finished = false
  146. // 重新加载数据
  147. // 将 loading 设置为 true,表示处于加载状态
  148. this.loading = true
  149. this.onLoad()
  150. },
  151. //钉钉授权
  152. getAuthconfig() {
  153. this.$api.user.authconfig({
  154. url: location.origin + '/'
  155. }).then((response) => {
  156. if (response.data.code == 0) {
  157. if (dd.env.platform != 'notInDingTalk') {
  158. //该方法必须带上,用来捕获鉴权出现的异常信息,否则不方便排查出现的问题
  159. dd.ready(() => {
  160. dd.runtime.permission.requestAuthCode({
  161. corpId: response.data.data.corpId, // 企业id
  162. onSuccess: (info) => {
  163. localStorage.setItem('hsayi-token', info.code);
  164. this.getUserInfo();
  165. },
  166. onFail: function (err) {
  167. console.log(err);
  168. this.pageLoading = true;
  169. this.vshowList = false;
  170. alert('dd error: ' + JSON.stringify(err));
  171. }
  172. });
  173. });
  174. dd.biz.navigation.setRight({
  175. show: false, //控制按钮显示, true 显示, false 隐藏, 默认true
  176. control: false, //是否控制点击事件,true 控制,false 不控制, 默认false
  177. showIcon: false, //是否显示icon,true 显示, false 不显示,默认true; 注:具体UI以客户端为准
  178. onSuccess: () => {},
  179. onFail: function (err) {
  180. console.log(err);
  181. alert('dd error: ' + JSON.stringify(err));
  182. }
  183. });
  184. } else {
  185. //本地调试不在钉钉上
  186. this.vshowList = false;
  187. localStorage.setItem('hsayi-token', '5c976f38445339f6b302390a61653b69');
  188. this.getUserInfo();
  189. }
  190. }
  191. }).catch(err => {
  192. console.log(err);
  193. this.pageLoading = true;
  194. });
  195. },
  196. // 获取用户信息
  197. getUserInfo() {
  198. this.$api.user.userinfo().then((res) => {
  199. if (res.data.code == 0) {
  200. localStorage.setItem('userId', res.data.data.userId);
  201. this.vshowList = true;
  202. this.onLoad();
  203. }
  204. }).catch(err => {
  205. console.log(err);
  206. this.pageLoading = true;
  207. });
  208. },
  209. ChangePageTitle(title) {
  210. if (dd.env.platform != 'notInDingTalk') {
  211. dd.ready(function () {
  212. dd.biz.navigation.setTitle({
  213. title: title, //控制标题文本,空字符串表示显示默认文本
  214. onSuccess: function (result) {
  215. console.log(result);
  216. },
  217. onFail: function (err) {
  218. console.log(err);
  219. }
  220. });
  221. });
  222. } else {
  223. document.title = title
  224. }
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="less" scoped>
  230. @import "index.less";
  231. </style>