index.vue 8.1 KB

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