index.vue 10 KB

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