index.vue 15 KB

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