浏览代码

小程序我的分享码

lifanagju_citu 7 月之前
父节点
当前提交
c73fe3b2da
共有 3 个文件被更改,包括 100 次插入1 次删除
  1. 14 1
      api/user.js
  2. 60 0
      pages/index/my.vue
  3. 26 0
      utils/base64src.js

+ 14 - 1
api/user.js

@@ -320,4 +320,17 @@ export const updatePersonAvatar = (avatar) => {
       showLoading: false
     }
   })
-}
+}
+
+// 获取职位分享小程序二维码
+export const getJobAdvertisedShareQrcode = (data) => {
+  return request({
+    url: '/app-api/menduner/system/social-user/wxa-qrcode',
+    method: 'POST',
+    data,
+    custom: {
+      auth: true,
+      showLoading: false
+    }
+  })
+}

+ 60 - 0
pages/index/my.vue

@@ -42,6 +42,15 @@
 				<uni-popup-dialog type="warn" cancelText="取消" confirmText="确定" title="系统提示" content="确认退出账号?" @confirm="handleLogoutConfirm"
 					@close="handleLogoutClose"></uni-popup-dialog>
 			</uni-popup>
+			<uni-popup ref="shareQrCodePopup" type="dialog">
+				<view class="shareQrCodePopupContent">
+					<view class="color-primary text">邀请用户注册领50积分</view>
+					<view class="qrCode">
+						<image :src="shareUrl" style="width: 200px;height: 200px;"></image>
+					</view>
+					<!-- <button v-if="shareUrl" class="send-button ss-m-b-30" @tap="handleSaveShareUrl">保存</button> -->
+				</view>
+			</uni-popup>
 		</view>
 	</layout-page>
 </template>
@@ -55,6 +64,8 @@ import { getAccessToken } from '@/utils/request'
 import layoutPage from '@/layout'
 import { showAuthModal } from '@/hooks/useModal'
 import { onShow } from '@dcloudio/uni-app'
+import { getJobAdvertisedShareQrcode } from '@/api/user'
+// import { base64src } from '@/utils/base64src.js'
 // 设置自定义tabbar选中值
 onShow(() => {
     const currentPage = getCurrentPages()[0];  // 获取当前页面实例
@@ -68,12 +79,14 @@ const useUserStore = userStore()
 const baseInfo = computed(() => useUserStore?.baseInfo)
 const userInfo = computed(() => useUserStore?.userInfo)
 const popup = ref()
+const shareQrCodePopup = ref()
 const itemList = [
 	{ title: "我的关注", path: "/pagesA/collect/index", icon: "list" },
 	{ title:'关注我的', path:'/pagesA/seenMe/index', icon:'staff' }
 ]
 
 const list = [
+	{	title: '我的分享码',	path: 'shareQrCode'	},					
 	{	title: '在线简历',	path: '/pagesA/resumeOnline/index'	},					
 	{	title: '附件简历',	path: '/pagesA/resume/index'	},					
 	{ title: '面试管理', path: '/pagesA/interview/index' },
@@ -108,11 +121,43 @@ const handleToLink = (item) => {
 		showAuthModal()
 		return
 	}
+  if (item.path === 'shareQrCode') {
+		handleShareCode()
+		return
+	}
 	uni.navigateTo({
 		url: item.path
 	})
 }
 
+const shareUrl = ref()
+// 生成分享二维码
+const handleShareCode = async () => {
+	const userId = useUserStore?.accountInfo?.userId || ''
+	if (!userId) {
+		uni.showToast({
+			title: '请先登录',
+			icon: 'none'
+		})
+	}
+	const query = {
+		scene: 'shareId=' + userId,
+		path: 'pages/login/index',
+		width: 200,
+		autoColor: false,
+		checkPath: true,
+		hyaline: true
+	}
+	const res = await getJobAdvertisedShareQrcode(query)
+	shareUrl.value = res?.data ? 'data:image/png;base64,' + res.data : ''
+	shareQrCodePopup.value.open()
+}
+
+// 保存到本地
+const handleSaveShareUrl = async () => {
+	const convertData = await base64src(shareUrl.value, '我的分享码')
+}
+
 // 登录
 const handleTap = () => {
 	if (!useUserStore.isLogin) {
@@ -177,4 +222,19 @@ const handleLogoutConfirm = () => {
 .parent:first-child{
 	margin: 0 0 20rpx 30rpx;
 }
+.shareQrCodePopupContent {
+	// width: 80vw;
+	// display: flex;
+	// flex-direction: column;
+	margin: 50rpx;
+	padding: 50rpx;
+	text-align: center;
+	background-color: #fff;
+	.text {
+		margin-bottom: 20px;
+	}
+	.qrCode {
+		margin-left: 4px;
+	}
+}
 </style>

+ 26 - 0
utils/base64src.js

@@ -0,0 +1,26 @@
+const fsm = wx.getFileSystemManager();
+
+function base64src(base64data, fileName) {
+  fileName = fileName || 'file_base64src'; //自定义文件名
+  const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || [];
+  if (!format) {
+    return (new Error('ERROR_BASE64SRC_PARSE'));
+  }
+  const filePath = `${wx.env.USER_DATA_PATH}/${fileName}.${format}`;
+  const buffer = wx.base64ToArrayBuffer(bodyData);
+  return new Promise((resolve, reject) =>{
+    fsm.writeFile({
+        filePath,
+        data: buffer,
+        encoding: 'binary',
+        success() {
+            resolve(filePath);
+        },
+        fail() {
+            reject(new Error('ERROR_BASE64SRC_WRITE'));
+        },
+    });
+  })
+};
+
+export { base64src };