index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <div class="body">
  3. <van-swipe class="my-swipe" :autoplay="3000" :height="200" indicator-color="white">
  4. <van-swipe-item v-for="(item, index) in images" :key="index" class="swipe-img">
  5. <img :src="item"/>
  6. </van-swipe-item>
  7. </van-swipe>
  8. <van-grid :column-num="3">
  9. <van-grid-item v-for="(item,index) in routers" :key="index" :icon="item.icon" :text="item.name"
  10. :info="(item.name=='消息记录'&&unreadNum>0)?unreadNum:''"
  11. :to="item.url">
  12. </van-grid-item>
  13. </van-grid>
  14. <div class="tip" v-if="isCorpWX">
  15. 工时报表统计等更多功能,请从PC端企业微信进入
  16. </div>
  17. <div class="tip" v-if="!isCorpWX">
  18. 体验报表统计等更多功能,尽在PC端<br>
  19. 网页用户访问http://worktime.ttkuaiban.com,钉钉用户直接从钉钉PC端进入工时管家
  20. </div>
  21. <Footer page="index"></Footer>
  22. </div>
  23. </template>
  24. <script>
  25. import Footer from "@/components/Footer";
  26. export default {
  27. data() {
  28. return {
  29. isCorpWX:false,
  30. isWX:false,
  31. user: JSON.parse(localStorage.userInfo),
  32. unreadNum:0,
  33. images: [
  34. // require('../../assets/img/index/banner_1.png'),
  35. require('../../assets/img/index/banner4.jpeg'),
  36. // require('../../assets/img/index/banner_3.png'),
  37. ],
  38. routers: [],
  39. };
  40. },
  41. created() {
  42. },
  43. mounted() {
  44. // if(this.user.companyName == '比基尼小镇'){
  45. // let consoleScript = document.createElement("script");
  46. // consoleScript.src = "https://cdn.bootcss.com/vConsole/3.3.4/vconsole.min.js";
  47. // consoleScript.onload = function () {
  48. // new VConsole()
  49. // }
  50. // document.head.appendChild(consoleScript);
  51. // }
  52. // console.log('userNameNeedTranslate',window.location.href);
  53. if(this.user.userNameNeedTranslate == '1'){
  54. this.agentConfig()
  55. }
  56. var ua = navigator.userAgent.toLowerCase();
  57. if (ua.indexOf("wxwork") > 0) {
  58. this.isCorpWX = true;
  59. } else if (ua.indexOf("micromessenger") > 0) {
  60. this.isWX = true;
  61. }
  62. if (this.user.company.packageEngineering == 1) {
  63. this.routers.push(
  64. {
  65. name: '专业审核',
  66. url: '/profession_review',
  67. icon: 'todo-list-o'
  68. });
  69. }
  70. var list = this.user.moduleList
  71. for (var i in list) {
  72. if(list[i].name == '工时报告') {
  73. this.routers.push({name: '查看日报',url: '/calendar',icon: 'description'})
  74. this.routers.push({name: '填写日报',url: '/edit',icon: 'edit'})
  75. // if (this.user.companyId == 817 || this.user.companyId == 7 || this.user.companyId == 10) {
  76. this.routers.push({name: '按周填报',url: '/weekEdit',icon: 'records'})
  77. // }
  78. }
  79. if(list[i].name == '待办任务') {
  80. this.routers.push({
  81. name: '待办任务',
  82. url: '/task',
  83. icon: 'coupon-o'
  84. });
  85. }
  86. if(list[i].name == '项目报告审核') {
  87. this.routers.push({name: '项目报告审核',url: '/review',icon: 'todo-list-o'})
  88. }
  89. if(list[i].name == '项目管理') {
  90. this.routers.push({name: '项目管理',url: '/project',icon: 'label-o'})
  91. }
  92. if(list[i].name == '导入日报审核') {
  93. this.routers.push({name: '导入日报审核',url: '/audit',icon: 'label-o'})
  94. }
  95. }
  96. if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
  97. this.routers.push(
  98. {
  99. name: '部门审核',
  100. url: '/department_review',
  101. icon: 'todo-list-o'
  102. });
  103. }
  104. this.routers.push({
  105. name: '消息记录',
  106. url: '/msg',
  107. icon: 'todo-list-o',
  108. info: this.unreadNum
  109. });
  110. this.getMessage();
  111. this.bindIfNessary();
  112. if (localStorage.userInfo != null) {
  113. this.getAccountInfo();
  114. }
  115. this.getMessage();
  116. this.bindIfNessary();
  117. if (localStorage.userInfo != null) {
  118. this.getAccountInfo();
  119. }
  120. },
  121. components: {
  122. Footer
  123. },
  124. methods: {
  125. // 获取企业微信参数
  126. agentConfig(){
  127. let curUrl = window.location.href.split('#')[0]
  128. this.$axios.post('/wxcorp/getCorpWXConfig',{
  129. url: curUrl,
  130. token: this.user.id
  131. }).then(res => {
  132. if(res.code == 'ok'){
  133. wx.config({
  134. beta: true,
  135. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  136. appId: res.data.appid, // 必填,公众号的唯一标识
  137. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  138. nonceStr: res.data.noncestr, // 必填,生成签名的随机串
  139. signature: res.data.sign, // 必填,签名,见附录1
  140. jsApiList: ['chooseImage','previewImage','uploadImage','downloadImage','previewFile','getLocation','agentConfig']
  141. })
  142. let that = this
  143. wx.ready(function(){
  144. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  145. that.$axios.post('/wxcorp/getCorpWXAgentConfig', {
  146. url: curUrl,
  147. token: that.user.id
  148. }).then(res => {
  149. if(res.code == 'ok'){
  150. wx.agentConfig({
  151. corpid: res.data.corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
  152. agentid: res.data.agentid, // 必填,企业微信的应用id (e.g. 1000247)
  153. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  154. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  155. signature: res.data.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
  156. jsApiList: ['selectExternalContact'], //必填,传入需要使用的接口名称
  157. success: function (result) {
  158. // console.log(result, '请求微信成功')
  159. // console.log(window, 'window')
  160. // wx.agentConfig成功回调后,WWOpenData 才会注入到 window 对象上面
  161. window.WWOpenData.bind(document.querySelector('ww-open-data'))
  162. },
  163. fail: function (res) {
  164. // console.log('查看错误信息', res)
  165. if (res.errMsg.indexOf('function not exist') > -1) {
  166. alert('版本过低请升级')
  167. }
  168. },
  169. })
  170. }
  171. }).catch(err => {
  172. if (err.errMsg.indexOf('function not exist') > -1) {
  173. alert('版本过低请升级')
  174. }
  175. })
  176. });
  177. }
  178. }).catch(err => {
  179. })
  180. },
  181. //获取账户信息
  182. getAccountInfo() {
  183. this.$axios.get('/user/loginByUserId', {params:{userId: this.user.id}})
  184. .then(res => {
  185. // console.log(res);
  186. if (res.code == 'error') {
  187. localStorage.errorMsg = res.msg;
  188. //账号信息有问题,不能使用。
  189. this.$router.push("/error");
  190. } else {
  191. localStorage.userInfo = JSON.stringify(res.data);
  192. this.user = res.data;
  193. }
  194. }).catch(err=> {
  195. alert('err=' + err);
  196. });
  197. },
  198. bindIfNessary() {
  199. let href = window.location.href;
  200. var requestUrl = "";
  201. if (this.isCorpWX && (this.user.corpwxUserid == null|| this.user.corpwxUserid == undefined || this.user.corpwxUserid == 'undefined')) {//优先检查企业微信环境
  202. requestUrl = "/wxcorp/bindCorpWeiXin";
  203. } else if (this.isWX && (this.user.wxOpenid == null || this.user.wxOpenid == undefined || this.user.wxOpenid == 'undefined')) {
  204. requestUrl = "/wechat/bindWeiXin";
  205. }
  206. if (requestUrl.length > 0) {
  207. // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
  208. //会自动跳转到首页
  209. // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
  210. if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
  211. var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
  212. var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
  213. // var urlLeft = url.substring(0, jingPosit);//url左侧部分
  214. var urlRight = url.substring(jingPosit, url.length); //url右侧部分
  215. // console.log('urlRight=' + urlRight);
  216. // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
  217. //获取code
  218. var code = urlRight.substring('?code='.length,urlRight.indexOf('#/index'));
  219. if (code.indexOf('&state=1') > 0) {
  220. code = code.substring(0, code.indexOf('&state=1'));
  221. }
  222. //调用后台接口,注册用户
  223. // console.log('获取到code=='+code);
  224. this.$axios.get(requestUrl, {params:{code:code, userId: this.user.id}})
  225. .then(res => {
  226. // console.log(res);
  227. if (res == null) {
  228. this.$toast.fail('绑定失败');
  229. } else if(res.errcode != null) {
  230. //报错了
  231. console.log(res.errmsg);
  232. } else {
  233. //获取openId
  234. if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
  235. || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
  236. localStorage.userInfo = JSON.stringify(res.data);
  237. // console.log('绑定成功');
  238. this.user = res.data;
  239. window.location.href = '/#/my/center';
  240. }
  241. }
  242. }).catch(err=> {
  243. alert('err=' + err);
  244. });
  245. }
  246. }
  247. },
  248. //获取消息
  249. getMessage() {
  250. this.$axios.post("/information/list", {
  251. })
  252. .then(res => {
  253. if(res.code == "ok") {
  254. var list = res.data;
  255. this.unreadNum = list.filter(l=>l.checked==0).length;
  256. // console.log(this.unreadNum);
  257. }
  258. }).catch(err=> {this.$toast.clear();});
  259. },
  260. },
  261. activated(){
  262. this.getMessage()
  263. }
  264. };
  265. </script>
  266. <style lang="less" scoped>
  267. .swipe-img {
  268. img {
  269. width: 100%;
  270. height: 100%;
  271. }
  272. }
  273. .body {
  274. height: calc(100vh - 50px);
  275. position: relative;
  276. }
  277. .tip {
  278. position: absolute;
  279. width: 100%;
  280. bottom: 5px;
  281. font-size: 14px;
  282. color: #8f8f8f;
  283. margin-top: 20px;
  284. text-align: center;
  285. line-height: 20px;
  286. }
  287. </style>