index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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" @click="pfdClick(item)">
  12. </van-grid-item>
  13. </van-grid>
  14. <!-- <div class="tip" v-if="isCorpWX">
  15. 工时报表统计等更多功能,请从PC端企业微信进入
  16. </div> -->
  17. <!-- <van-icon v-if="isCorpWX" class="kefu" name="service-o" size="30" color="#20a0ff" @click="tokefu" /> -->
  18. <div v-if="isCorpWX" class="kefu" @click="tokefu"><img src="../../assets/icon/kefu.png" alt=""></div>
  19. <div class="tip" v-if="!isCorpWX">
  20. 体验报表统计等更多功能,尽在PC端<br>
  21. 网页用户访问http://worktime.ttkuaiban.com,钉钉用户直接从钉钉PC端进入工时管家
  22. </div>
  23. <Footer ref="child" :key="key"></Footer>
  24. </div>
  25. </template>
  26. <script>
  27. import Footer from "@/components/Footer";
  28. import Vue from "vue";
  29. import { ImagePreview } from "vant";
  30. Vue.use(ImagePreview);
  31. export default {
  32. data() {
  33. return {
  34. isCorpWX:false,
  35. isWX:false,
  36. user: null,
  37. unreadNum:0,
  38. images: [
  39. // require('../../assets/img/index/banner_1.png'),
  40. require('../../assets/img/index/banner4.jpeg'),
  41. // require('../../assets/img/index/banner_3.png'),
  42. ],
  43. routers: [],
  44. key: 0,
  45. isSyncData: false
  46. };
  47. },
  48. created() {
  49. if(localStorage.userInfo) {
  50. this.user = JSON.parse(localStorage.userInfo)
  51. // 是否为钉钉同步
  52. this.isSyncData = this.user.timeType.syncDingding || this.user.timeType.syncFanwei;
  53. }
  54. },
  55. mounted() {
  56. //有错误信息,优先跳转到登录页面去
  57. if(window.location.href.indexOf('errorMsg') != '-1') {
  58. this.$router.push("/login");
  59. }
  60. var ua = navigator.userAgent.toLowerCase();
  61. if (ua.indexOf("wxwork") > 0) {
  62. this.isCorpWX = true;
  63. } else if (ua.indexOf("micromessenger") > 0) {
  64. this.isWX = true;
  65. }
  66. let that = this;
  67. //企业微信或个人微信是从后台授权后跳转过来的
  68. if (this.isCorpWX || this.isWX) {
  69. //后台自动授权登录的用户
  70. if(window.location.href.indexOf('userId') != '-1') {
  71. let href = window.location.href;
  72. var loginUserId = href.substring(href.indexOf("userId=")+"userId=".length);
  73. if (loginUserId.includes('#/')) {
  74. loginUserId = loginUserId.substring(0, loginUserId.indexOf('#/'));
  75. }
  76. that.getAccountInfo(loginUserId)
  77. } else {
  78. //存在一部分用户,没有绑定企业微信,进来后跳到登录页面,登录页面输入账号密码进来后不带userId
  79. if (this.user) {
  80. that.getAccountInfo(that.user.id);
  81. } else {
  82. that.$router.push("/login");
  83. }
  84. }
  85. } else {
  86. //其他情况,刷新用户信息
  87. if (localStorage.userInfo != null) {
  88. that.user = JSON.parse(localStorage.userInfo);
  89. that.getAccountInfo(that.user.id);
  90. }
  91. }
  92. if (this.user) {
  93. let userss = this.user;
  94. if(userss.companyId == '3454') {
  95. alert(`isMobFirstLogin = ${userss.isMobFirstLogin} $ userss.createTime = ${userss.createTime[0]} $ userss.roleName = ${userss.roleName}`)
  96. }
  97. if(userss.isMobFirstLogin == 1 && userss.createTime[0] > '2022' && userss.roleName == '超级管理员') {
  98. // 第一次登陆显示
  99. this.previewPicture()
  100. }
  101. }
  102. },
  103. components: {
  104. Footer
  105. },
  106. methods: {
  107. pfdClick(item) {
  108. if(item.name == '使用说明') {
  109. let url = 'http://celiang.oss-cn-hangzhou.aliyuncs.com/measurement/2022-01/18/75it6phpocqYFV1642488558220118.pdf'
  110. let name = '使用说明书'
  111. // 将要传过去的值
  112. this.previewPDF(url, name)
  113. }
  114. },
  115. // 预览pdf
  116. previewPDF(url, name) {
  117. this.$router.push({
  118. path: '/pdf',
  119. query: {
  120. url: '',
  121. name: name
  122. }
  123. })
  124. },
  125. // 图片预览
  126. previewPicture() {
  127. let that = this
  128. let arr = [
  129. 'https://mobworktime.ttkuaiban.com/upload/b9cf863819924106a65255ccffae446d.png',
  130. 'https://mobworktime.ttkuaiban.com/upload/65afcaed7ad84c51a309db69c888fe6c.png',
  131. 'https://mobworktime.ttkuaiban.com/upload/3452d33a68bb4092b04147e5482fd0e9.png',
  132. 'https://mobworktime.ttkuaiban.com/upload/af5b430f48b24b2683fb48a43deab98c.png',
  133. 'https://mobworktime.ttkuaiban.com/upload/b69779d86be44ef3a1d3585816fde5f3.png'
  134. ]
  135. ImagePreview({
  136. images: arr,
  137. startPosition: 0,
  138. showIndicators: true,
  139. closeable: true,
  140. onClose() {
  141. that.previewPictureClose()
  142. },
  143. });
  144. },
  145. // 处理关闭事件
  146. previewPictureClose() {
  147. this.$axios.post("/user/mobSkipGuidance", {
  148. })
  149. .then(res => {
  150. if(res.code == "ok") {
  151. let userss = JSON.parse(localStorage.userInfo)
  152. userss.isMobFirstLogin = 0
  153. localStorage.userInfo = JSON.stringify(userss);
  154. }
  155. }).catch(err=> {this.$toast.clear();});
  156. },
  157. tokefu(){
  158. wx.invoke('openThirdAppServiceChat', {
  159. }, function(res) {
  160. console.log('invoke',res);
  161. if (res.err_msg == "openThirdAppServiceChat:ok" || res.err_msg == "openThirdAppServiceChat:cancel") {
  162. }else{
  163. this.$toast.fail('请联系管理员添加客服');
  164. }
  165. }
  166. );
  167. },
  168. // 模块
  169. getModule() {
  170. if(this.user.userNameNeedTranslate == '1'){
  171. this.agentConfig()
  172. }
  173. if (this.user.company.packageEngineering == 1) {
  174. this.routers.push(
  175. {
  176. name: '专业审核',
  177. url: '/profession_review',
  178. icon: 'todo-list-o'
  179. });
  180. }
  181. var list = this.user.moduleList
  182. for (var i in list) {
  183. if(list[i].name == '工时报告') {
  184. this.routers.push({name: '查看日报',url: '/calendar',icon: 'description'})
  185. this.routers.push({name: '填写日报',url: '/edit',icon: 'edit'})
  186. // if (this.user.companyId == 817 || this.user.companyId == 7 || this.user.companyId == 10) {
  187. this.routers.push({name: '按周填报',url: '/weekEdit',icon: 'records'})
  188. // }
  189. }
  190. if(list[i].name == '待办任务') {
  191. this.routers.push({
  192. name: '待办任务',
  193. url: '/task',
  194. icon: 'coupon-o'
  195. });
  196. }
  197. if(list[i].name == '项目报告审核') {
  198. this.routers.push({name: '项目报告审核',url: '/review',icon: 'todo-list-o'})
  199. }
  200. if(list[i].name == '项目管理') {
  201. this.routers.push({name: '项目管理',url: '/project',icon: 'label-o'})
  202. }
  203. if(list[i].name == '导入日报审核') {
  204. this.routers.push({name: '导入日报审核',url: '/audit',icon: 'completed'})
  205. }
  206. if(!this.isSyncData) {
  207. if(list[i].name == '请假管理') {
  208. this.routers.push({name: '请假管理',url: '/applyLeave',icon: 'notes-o'})
  209. // this.routers.push({name: '请假审批',url: '/exaLeave',icon: 'completed'})
  210. // this.routers.push({name: '出差管理',url: '/awayOffice',icon: 'completed'})
  211. }
  212. if(list[i].name == '出差管理') {
  213. this.routers.push({name: '出差管理',url: '/awayOffice',icon: 'logistics'})
  214. }
  215. }
  216. if(list[i].name == '费用报销') {
  217. this.routers.push({
  218. name: '费用报销',
  219. url: '/expense',
  220. icon: 'balance-list-o'
  221. });
  222. }
  223. }
  224. if (this.user.manageDeptId != 0 && this.user.company.packageEngineering == 1) {
  225. this.routers.push(
  226. {
  227. name: '部门审核',
  228. url: '/department_review',
  229. icon: 'todo-list-o'
  230. });
  231. }
  232. this.routers.push({
  233. name: '消息记录',
  234. url: '/msg',
  235. icon: 'todo-list-o',
  236. info: this.unreadNum
  237. });
  238. // 针对超级管理员加使用说明
  239. if(this.user.roleName == '超级管理员') {
  240. this.routers.push(
  241. {
  242. name: '使用说明',
  243. // url: '/',
  244. icon: 'todo-list-o'
  245. });
  246. }
  247. },
  248. // 获取企业微信参数
  249. agentConfig(){
  250. let curUrl = window.location.href.split('#')[0]
  251. this.$axios.post('/wxcorp/getCorpWXConfig',{
  252. url: curUrl,
  253. token: this.user.id
  254. }).then(res => {
  255. if(res.code == 'ok'){
  256. wx.config({
  257. beta: true,
  258. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  259. appId: res.data.appid, // 必填,公众号的唯一标识
  260. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  261. nonceStr: res.data.noncestr, // 必填,生成签名的随机串
  262. signature: res.data.sign, // 必填,签名,见附录1
  263. jsApiList: ['chooseImage','previewImage','uploadImage','downloadImage','previewFile','getLocation','agentConfig']
  264. })
  265. let that = this
  266. wx.ready(function(){
  267. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
  268. that.$axios.post('/wxcorp/getCorpWXAgentConfig', {
  269. url: curUrl,
  270. token: that.user.id
  271. }).then(res => {
  272. if(res.code == 'ok'){
  273. wx.agentConfig({
  274. corpid: res.data.corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
  275. agentid: res.data.agentid, // 必填,企业微信的应用id (e.g. 1000247)
  276. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  277. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  278. signature: res.data.signature, // 必填,签名,见附录-JS-SDK使用权限签名算法
  279. jsApiList: ['selectExternalContact','openThirdAppServiceChat', 'openAppManage'], //必填,传入需要使用的接口名称
  280. success: function (result) {
  281. // console.log(result, '请求微信成功')
  282. // console.log(window, 'window')
  283. // wx.agentConfig成功回调后,WWOpenData 才会注入到 window 对象上面
  284. window.WWOpenData.bind(document.querySelector('ww-open-data'))
  285. // that.kefuShow = true
  286. },
  287. fail: function (res) {
  288. // console.log('查看错误信息', res)
  289. if (res.errMsg.indexOf('function not exist') > -1) {
  290. alert('版本过低请升级')
  291. } else {
  292. // alert('agentConfig出错:'+res.errMsg);
  293. }
  294. },
  295. })
  296. }
  297. }).catch(err => {
  298. if (err.errMsg.indexOf('function not exist') > -1) {
  299. alert('版本过低请升级')
  300. }else {
  301. // alert(res.errMsg);
  302. }
  303. })
  304. });
  305. wx.error(function(res){
  306. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
  307. // alert('wxConfig发生异常:'+JSON.stringify(res));
  308. // 企业第一次授权安装进入后会报not in reliable domain的错误,刷新后正常
  309. location.reload();
  310. });
  311. } else {
  312. // alert(''+res);
  313. }
  314. }).catch(err => {
  315. alert(err);
  316. })
  317. },
  318. //获取账户信息
  319. getAccountInfo(userId) {
  320. this.$axios.get('/user/loginByUserId', {params:{userId: userId}})
  321. .then(res => {
  322. // console.log(res);
  323. if (res.code == 'error') {
  324. localStorage.errorMsg = res.msg;
  325. //账号信息有问题,不能使用。
  326. this.$router.push("/error");
  327. } else {
  328. localStorage.userInfo = JSON.stringify(res.data);
  329. this.user = res.data;
  330. this.$refs.child.dealWith()
  331. this.key++
  332. this.getModule()
  333. this.getMessage();
  334. this.redirectIfNess();
  335. this.$forceUpdate()
  336. // this.bindIfNessary();
  337. }
  338. }).catch(err=> {
  339. alert('err=' + err);
  340. });
  341. },
  342. redirectIfNess() {
  343. var href = window.location.href;
  344. if (href.indexOf('path') > 0) {
  345. var path = href.split('path=')[1].split('&')[0];
  346. if (path == 'expense' || path == 'task') {
  347. this.$router.push(path);
  348. }
  349. }
  350. },
  351. bindIfNessary() {
  352. let href = window.location.href;
  353. var requestUrl = "";
  354. if (this.isCorpWX && (this.user.corpwxUserid == null|| this.user.corpwxUserid == undefined || this.user.corpwxUserid == 'undefined')) {//优先检查企业微信环境
  355. requestUrl = "/wxcorp/bindCorpWeiXin";
  356. } else if (this.isWX && (this.user.wxOpenid == null || this.user.wxOpenid == undefined || this.user.wxOpenid == 'undefined')) {
  357. requestUrl = "/wechat/bindWeiXin";
  358. }
  359. if (requestUrl.length > 0) {
  360. // localStorage.openId = 'o1L3L5lOrOl3_UEJjONaoT2Rne1I';
  361. //会自动跳转到首页
  362. // let href = 'http://hq.tangusoft.com/?code=011Ptjgc2rx1eI09Irgc2Rvsgc2PtjgF&state=1#/index';
  363. if (href.includes("com/?code")) { //url包括 com/?code 证明为从微信跳转回来的
  364. var url = href; //vue自动在末尾加了 #/ 符号,截取去掉
  365. var jingPosit = url.indexOf("com/") + 4; //获取域名结束的位置
  366. // var urlLeft = url.substring(0, jingPosit);//url左侧部分
  367. var urlRight = url.substring(jingPosit, url.length); //url右侧部分
  368. // console.log('urlRight=' + urlRight);
  369. // window.location = urlLeft + "#/home" + urlRight;//拼接跳转
  370. //获取code
  371. var code = urlRight.substring('?code='.length,urlRight.indexOf('#/index'));
  372. if (code.indexOf('&state=1') > 0) {
  373. code = code.substring(0, code.indexOf('&state=1'));
  374. }
  375. //调用后台接口,注册用户
  376. // console.log('获取到code=='+code);
  377. this.$axios.get(requestUrl, {params:{code:code, userId: this.user.id}})
  378. .then(res => {
  379. // console.log(res);
  380. if (res == null) {
  381. this.$toast.fail('绑定失败');
  382. } else if(res.errcode != null) {
  383. //报错了
  384. console.log(res.errmsg);
  385. } else {
  386. //获取openId
  387. if (res.data != null && ((this.isWX && res.data.wxOpenid != undefined)
  388. || (this.isCorpWX && res.data.corpwxUserid != undefined))) {
  389. localStorage.userInfo = JSON.stringify(res.data);
  390. // console.log('绑定成功');
  391. this.user = res.data;
  392. window.location.href = '/#/my/center';
  393. }
  394. }
  395. }).catch(err=> {
  396. alert('err=' + err);
  397. });
  398. }
  399. }
  400. },
  401. //获取消息
  402. getMessage() {
  403. this.$axios.post("/information/list", {
  404. })
  405. .then(res => {
  406. if(res.code == "ok") {
  407. var list = res.data;
  408. this.unreadNum = list.filter(l=>l.checked==0).length;
  409. // console.log(this.unreadNum);
  410. }
  411. }).catch(err=> {this.$toast.clear();});
  412. },
  413. },
  414. activated(){
  415. this.getMessage()
  416. },
  417. };
  418. </script>
  419. <style lang="less" scoped>
  420. .swipe-img {
  421. img {
  422. width: 100%;
  423. height: 100%;
  424. }
  425. }
  426. .body {
  427. height: calc(100vh - 50px);
  428. position: relative;
  429. }
  430. .kefu{
  431. position: fixed;
  432. right: 35px;
  433. bottom: 120px;
  434. width: 36px;
  435. height: 36px;
  436. background-color: #fff;
  437. z-index: 1000;
  438. border-radius: 50%;
  439. img{
  440. margin: 4px;
  441. width: 28px;
  442. height: 28px;
  443. }
  444. }
  445. .tip {
  446. position: absolute;
  447. width: 100%;
  448. bottom: 5px;
  449. font-size: 14px;
  450. color: #8f8f8f;
  451. margin-top: 20px;
  452. text-align: center;
  453. line-height: 20px;
  454. }
  455. </style>