index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="content">
  3. <div class="self-inf">
  4. <div class="img-name-box" v-if="isAuth">
  5. <image :src="userHeadImg" class="heade-img" mode="aspectFill"></image>
  6. <p class="nickname">{{ userNickName }}</p>
  7. </div>
  8. <view class="img-name-box" v-if="!isAuth">
  9. <image src="/static/auth-icon.png" class="heade-img" mode="aspectFill"></image>
  10. <button @click="goAuthPage()" class="auth-btn">授权登录</button>
  11. </view>
  12. <image class="bg-img" :src="swiperBackground" mode="aspectFill"></image>
  13. </div>
  14. <div class="options">
  15. <div v-for="(item, idx) in list" :key="idx" class="options-item" @click="goDetailFn(idx, item.url)" v-if="item.isShow">
  16. <div class="img-box">
  17. <img :src="item.icon" alt="" class="options-item-img" />
  18. </div>
  19. <div class="options-item-name">
  20. {{ item.name }}
  21. </div>
  22. </div>
  23. </div>
  24. <!-- <button class="submit-btn" @click="goUpload()">上传</button> -->
  25. </view>
  26. </template>
  27. <script>
  28. import md5 from "@/common/md5.js";
  29. export default {
  30. components: {
  31. },
  32. data() {
  33. return {
  34. isAuth: true,
  35. userHeadImg: "",
  36. userNickName: "",
  37. userscanCode:"",
  38. list: [
  39. {
  40. icon: "/static/upload.png",
  41. name: "内容上传" ,
  42. url: "/pages/index/upload/upload",
  43. isShow:false,
  44. },
  45. {
  46. icon: "/static/sign.png",
  47. name: "发布记录" ,
  48. url: "/pages/index/record/record",
  49. isShow:false,
  50. },
  51. {
  52. icon: "/static/scan.png",
  53. name: "扫码" ,
  54. // url: "/pages/index/scanCode/index",
  55. isShow:true,
  56. },
  57. {
  58. icon: "/static/self-icon.png",
  59. name: "个人信息" ,
  60. // url: "/pages/",
  61. isShow:true,
  62. },
  63. {
  64. icon: "/static/org-icon.png",
  65. name: "组织成员" ,
  66. // url: "/pages/index/scanCode/index",
  67. isShow:true,
  68. },
  69. {
  70. icon: "/static/explain-icon.png",
  71. name: "后台说明" ,
  72. // url: "/pages/index/record/record",
  73. isShow:true,
  74. },
  75. {
  76. icon: "/static/back.png",
  77. name: "退出登录" ,
  78. // url: "/pages/index/scanCode/index",
  79. isShow:true,
  80. },
  81. ],
  82. };
  83. },
  84. async onLoad() {
  85. // setTimeout(()=>{
  86. // this.getUserInfo()
  87. // },1000)
  88. await this.$getOpenId
  89. this.getUserInfo()
  90. },
  91. onShow() {
  92. },
  93. methods: {
  94. goAuthPage() {
  95. uni.navigateTo({
  96. url: "./auth/index",
  97. });
  98. },
  99. goUpload(){
  100. let that = this;
  101. if(!that.isAuth){
  102. uni.showToast({
  103. title: "您还没有授权",
  104. duration: 2500,
  105. icon: "none",
  106. });
  107. return;
  108. }else {
  109. uni.navigateTo({
  110. url: "/pages/index/upload/upload",
  111. })
  112. }
  113. },
  114. getUserInfo() {
  115. let md5Sign = md5(
  116. "method=" +
  117. "user" +
  118. "&timestamp=" +
  119. getApp().globalData.globalTimestamp +
  120. "&secret=" +
  121. getApp().globalData.secret
  122. );
  123. let url =
  124. getApp().globalData.shareUrl +
  125. "api/api.php" +
  126. "?method=user&action=info_by_openid&timestamp=" +
  127. getApp().globalData.globalTimestamp +
  128. "&sign=" +
  129. md5Sign;
  130. uni.request({
  131. url: url,
  132. method: "POST",
  133. header: {
  134. "content-type": "application/x-www-form-urlencoded",
  135. },
  136. data: {
  137. openid:getApp().globalData.open_id,
  138. },
  139. success: (res) => {
  140. if (res.data.code === 200) {
  141. if (res.data.data.nickname) {
  142. this.isAuth = true;
  143. this.userHeadImg = res.data.data.headimg;
  144. this.userNickName = res.data.data.nickname;
  145. getApp().globalData.user_department = res.data.data.department;
  146. getApp().globalData.user_real_name = res.data.data.real_name;
  147. }else {
  148. this.isAuth = false;
  149. getApp().globalData.globalAuth = false;
  150. }
  151. }
  152. },
  153. fail: () => {
  154. console.log("连接失败");
  155. },
  156. });
  157. },
  158. uploadUserInfo(name,head){
  159. },
  160. getAuth() {
  161. // uni.getUserProfile({
  162. // desc:'登录',
  163. // success:(res)=> {
  164. // this.userHeadImg = res.userInfo.avatarUrl;
  165. // this.userNickName = res.userInfo.nickName;
  166. // this.uploadUserInfo(res.userInfo.nickName,res.userInfo.avatarUrl)
  167. // this.isAuth = true;
  168. // getApp().globalData.isAuth = true;
  169. // },
  170. // fail:(err)=> {
  171. // console.log(err)
  172. // getApp().globalData.isAuth = false;
  173. // getApp().globalData.globalAuth = false;
  174. // this.isAuth = false;
  175. // }
  176. // })
  177. },
  178. getUserPhone(){
  179. },
  180. codeReg(strs){
  181. let reg = /\[(.*?)\]/gi;
  182. let str = strs;
  183. let tmp = str.match(reg) , result = '';
  184. if (tmp) {
  185. for (let i = 0; i < tmp.length; i++) {
  186. result = tmp[i].replace(reg, "$1")
  187. }
  188. } else {
  189. console.log("no match.");
  190. }
  191. console.log(result)
  192. this.getScanCode(result)
  193. },
  194. getScanCode(codeRes) {
  195. let md5Sign = md5(
  196. "method=" +
  197. "user" +
  198. "&timestamp=" +
  199. getApp().globalData.globalTimestamp +
  200. "&secret=" +
  201. getApp().globalData.secret
  202. );
  203. let url =
  204. getApp().globalData.shareUrl +
  205. "api/api.php" +
  206. "?method=user&action=qrcode_login&timestamp=" +
  207. getApp().globalData.globalTimestamp +
  208. "&sign=" +
  209. md5Sign;
  210. uni.request({
  211. url: url,
  212. method: "POST",
  213. header: {
  214. "content-type": "application/x-www-form-urlencoded",
  215. },
  216. data: {
  217. openid:getApp().globalData.open_id,
  218. qrcode:codeRes
  219. },
  220. success: (res) => {
  221. if (res.data.code === 200) {
  222. uni.showToast({
  223. title:res.data.msg,
  224. icon:'none'
  225. })
  226. } else {
  227. uni.showToast({
  228. title:res.data.msg,
  229. icon:'none'
  230. })
  231. }
  232. },
  233. fail: () => {
  234. console.log("连接失败");
  235. },
  236. });
  237. },
  238. goDetailFn(index, url) {
  239. let that = this;
  240. if(!that.isAuth){
  241. uni.showToast({
  242. title: "您还没有授权",
  243. duration: 2500,
  244. icon: "none",
  245. });
  246. return;
  247. }
  248. switch (index) {
  249. case 0: //内容上传
  250. uni.navigateTo({
  251. url,
  252. });
  253. break;
  254. case 1: //发布记录
  255. uni.navigateTo({
  256. url,
  257. });
  258. break;
  259. case 2: //扫一扫
  260. uni.scanCode({
  261. success: function (res) {
  262. console.log('条码类型:' + res.scanType);
  263. console.log('条码内容:' + res.result);
  264. that.codeReg(res.result)
  265. }
  266. });
  267. break;
  268. }
  269. },
  270. },
  271. };
  272. </script>
  273. <style lang="scss" scoped>
  274. .content {
  275. display: flex;
  276. flex-direction: column;
  277. .self-inf {
  278. position: relative;
  279. height: 360rpx;
  280. width: 100%;
  281. display: flex;
  282. // margin-bottom: 80rpx;
  283. background-color: #c2e3e6;
  284. // border-radius: 0rpx 0rpx 100% 100%;
  285. .img-name-box {
  286. height: 150rpx;
  287. margin-top:80rpx;
  288. display: flex;
  289. align-items: center;
  290. z-index: 99999;
  291. .auth-btn {
  292. margin-left: 30rpx;
  293. margin-top: 20rpx;
  294. font-size: 28rpx;
  295. background-color: #02a7f0;
  296. color: #fff;
  297. }
  298. .heade-img {
  299. z-index: 1;
  300. width: 100rpx;
  301. height: 100rpx;
  302. border-radius: 50%;
  303. margin-left: 80rpx;
  304. }
  305. }
  306. .bg-img {
  307. z-index: -1;
  308. position: absolute;
  309. width: 100%;
  310. height: 100%;
  311. // border-radius: 0rpx 0rpx 70rpx 70rpx;
  312. }
  313. .nickname {
  314. font-weight: 600;
  315. font-size: 28rpx;
  316. margin-left: 30rpx;
  317. margin-top: 20rpx;
  318. color: #ffffff;
  319. letter-spacing: 1rpx;
  320. }
  321. }
  322. .options {
  323. padding: 0 70rpx 0 70rpx;
  324. z-index: 99;
  325. position: relative;
  326. top: -100rpx;
  327. .options-item {
  328. background-color: #fff;
  329. display: flex;
  330. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  331. border-radius: 32rpx;
  332. margin-top: 30rpx;
  333. height: 75px;
  334. align-items: center;
  335. .img-box {
  336. margin-left: 40rpx;
  337. .options-item-img {
  338. width: 56rpx;
  339. height: 56rpx;
  340. }
  341. }
  342. .options-item-name {
  343. margin-left: 40rpx;
  344. font-weight: 600;
  345. font-size: 30rpx;
  346. margin-bottom: 10rpx;
  347. }
  348. }
  349. }
  350. }
  351. .fontGrey {
  352. color: $uni-text-color-grey;
  353. }
  354. .submit-btn {
  355. color: white;
  356. font-weight: normal;
  357. width: 70%;
  358. border-radius: 20rpx;
  359. background-color: #02a7f0;
  360. margin: 50rpx auto;
  361. }
  362. </style>