index.vue 16 KB

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