index.vue 7.6 KB

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