index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. let index = this.active + 1;
  43. this.list = this[`list${index}`]; // this.list1
  44. },
  45. mounted() {
  46. var ua = navigator.userAgent.toLowerCase();
  47. if (ua.indexOf("wxwork") > 0) {
  48. this.isCorpWX = true;
  49. } else if (ua.indexOf("micromessenger") > 0) {
  50. this.isWX = true;
  51. }
  52. if (this.user.company.packageEngineering == 1) {
  53. this.routers.push(
  54. {
  55. name: '专业审核',
  56. url: '/profession_review',
  57. icon: 'todo-list-o'
  58. });
  59. }
  60. var list = this.user.moduleList
  61. for (var i in list) {
  62. if(list[i].name == '工时报告') {
  63. this.routers.push({name: '查看日报',url: '/calendar',icon: 'description'})
  64. this.routers.push({name: '填写日报',url: '/edit',icon: 'edit'})
  65. this.routers.push({name: '按周填报',url: '/weekEdit',icon: 'edit'})
  66. }
  67. if(list[i].name == '项目报告审核') {
  68. this.routers.push({name: '项目报告审核',url: '/review',icon: 'todo-list-o'})
  69. }
  70. if(list[i].name == '项目管理') {
  71. this.routers.push({name: '项目管理',url: '/project',icon: 'label-o'})
  72. }
  73. if(list[i].name == '导入日报审核') {
  74. this.routers.push({name: '导入日报审核',url: '/audit',icon: 'label-o'})
  75. }
  76. }
  77. if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
  78. this.routers.push(
  79. {
  80. name: '部门审核',
  81. url: '/department_review',
  82. icon: 'todo-list-o'
  83. });
  84. }
  85. this.routers.push({
  86. name: '消息记录',
  87. url: '/msg',
  88. icon: 'todo-list-o',
  89. info: this.unreadNum
  90. });
  91. this.getMessage();
  92. this.bindIfNessary();
  93. if (localStorage.userInfo != null) {
  94. this.getAccountInfo();
  95. }
  96. // this.routers.push({
  97. // name: '自动计时',
  98. // url: '/timetool',
  99. // icon: 'clock-o',
  100. // info: this.unreadNum
  101. // });
  102. // if (this.user.companyId==634 || this.user.companyId==7 || this.user.companyId==431) {
  103. // this.routers.push({
  104. // name: '请假审批',
  105. // url: '/exaLeave',
  106. // icon: 'todo-list-o',
  107. // });
  108. // }
  109. this.getMessage();
  110. this.bindIfNessary();
  111. if (localStorage.userInfo != null) {
  112. this.getAccountInfo();
  113. }
  114. },
  115. components: {
  116. Footer
  117. },
  118. methods: {
  119. //获取账户信息
  120. getAccountInfo() {
  121. this.$axios.get('/user/loginByUserId', {params:{userId: this.user.id}})
  122. .then(res => {
  123. console.log(res);
  124. if (res.code == 'error') {
  125. localStorage.errorMsg = res.msg;
  126. //账号信息有问题,不能使用。
  127. this.$router.push("/error");
  128. } else {
  129. localStorage.userInfo = JSON.stringify(res.data);
  130. this.user = res.data;
  131. }
  132. }).catch(err=> {
  133. alert('err=' + err);
  134. });
  135. },
  136. bindIfNessary() {
  137. let href = window.location.href;
  138. var requestUrl = "";
  139. if (this.isCorpWX && (this.user.corpwxUserid == null|| this.user.corpwxUserid == undefined || this.user.corpwxUserid == 'undefined')) {//优先检查企业微信环境
  140. requestUrl = "/wxcorp/bindCorpWeiXin";
  141. } else if (this.isWX && (this.user.wxOpenid == null || this.user.wxOpenid == undefined || this.user.wxOpenid == 'undefined')) {
  142. requestUrl = "/wechat/bindWeiXin";
  143. }
  144. if (requestUrl.length > 0) {
  145. // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
  146. //会自动跳转到首页
  147. // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
  148. if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
  149. var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
  150. var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
  151. // var urlLeft = url.substring(0, jingPosit);//url左侧部分
  152. var urlRight = url.substring(jingPosit, url.length); //url右侧部分
  153. console.log('urlRight=' + urlRight);
  154. // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
  155. //获取code
  156. var code = urlRight.substring('?code='.length,urlRight.indexOf('#/index'));
  157. if (code.indexOf('&state=1') > 0) {
  158. code = code.substring(0, code.indexOf('&state=1'));
  159. }
  160. //调用后台接口,注册用户
  161. console.log('获取到code=='+code);
  162. this.$axios.get(requestUrl, {params:{code:code, userId: this.user.id}})
  163. .then(res => {
  164. console.log(res);
  165. if (res == null) {
  166. this.$toast.fail('绑定失败');
  167. } else if(res.errcode != null) {
  168. //报错了
  169. console.log(res.errmsg);
  170. } else {
  171. //获取openId
  172. if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
  173. || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
  174. localStorage.userInfo = JSON.stringify(res.data);
  175. console.log('绑定成功');
  176. this.user = res.data;
  177. window.location.href = '/#/my/center';
  178. }
  179. }
  180. }).catch(err=> {
  181. alert('err=' + err);
  182. });
  183. }
  184. }
  185. },
  186. //获取消息
  187. getMessage() {
  188. this.$axios.post("/information/list", {
  189. })
  190. .then(res => {
  191. if(res.code == "ok") {
  192. var list = res.data;
  193. this.unreadNum = list.filter(l=>l.checked==0).length;
  194. console.log(this.unreadNum);
  195. }
  196. }).catch(err=> {this.$toast.clear();});
  197. },
  198. },
  199. activated(){
  200. this.getMessage()
  201. }
  202. };
  203. </script>
  204. <style lang="less" scoped>
  205. .swipe-img {
  206. img {
  207. width: 100%;
  208. height: 100%;
  209. }
  210. }
  211. .body {
  212. height: calc(100vh - 50px);
  213. position: relative;
  214. }
  215. .tip {
  216. position: absolute;
  217. width: 100%;
  218. bottom: 5px;
  219. font-size: 14px;
  220. color: #8f8f8f;
  221. margin-top: 20px;
  222. text-align: center;
  223. line-height: 20px;
  224. }
  225. </style>