Bladeren bron

优化扫码添加设备 分享设备 登录重定向 界面图标颜色

“shengjie.huang” 1 jaar geleden
bovenliggende
commit
840017380e

+ 3 - 3
pages.config.ts

@@ -17,12 +17,12 @@ export default defineUniPages({
     },
   },
   tabBar: {
-    color: '#999999',
-    selectedColor: '#FF8D1A',
+    color: '#333333',
+    selectedColor: '#1487f4',
     backgroundColor: '#F8F8F8',
     borderStyle: 'black',
     height: '50px',
-    fontSize: '10px',
+    fontSize: '12px',
     iconWidth: '24px',
     spacing: '3px',
     list: [

+ 0 - 4
src/App.vue

@@ -4,10 +4,6 @@ import { useUserStore } from '@/store'
 
 onLaunch(() => {
   console.log('App Launch')
-  // 已经有登录过token的情况下, 更新token
-  if (useUserStore().isLogined) {
-    useUserStore().wxLogin().then((token) => { })
-  }
 })
 onShow(() => {
   console.log('App Show')

+ 3 - 3
src/pages.json

@@ -14,12 +14,12 @@
     }
   },
   "tabBar": {
-    "color": "#999999",
-    "selectedColor": "#FF8D1A",
+    "color": "#333333",
+    "selectedColor": "#1487f4",
     "backgroundColor": "#F8F8F8",
     "borderStyle": "black",
     "height": "50px",
-    "fontSize": "10px",
+    "fontSize": "12px",
     "iconWidth": "24px",
     "spacing": "3px",
     "list": [

+ 12 - 0
src/pages/assistant/detail.vue

@@ -149,7 +149,19 @@ function handleSubmit() {
 }
 
 onLoad((option) => {
+  // 通过分享传参
   type.value = option.type || "add"
+  if (type.value == 'add' && option.hostname && option.asname) {
+    formData.value.hostname = option.hostname
+    formData.value.asname = option.asname
+    message.confirm({
+      msg: `是否添加设备"${option.asname}"到我的打印助手`,
+      closeOnClickModal: false,
+    }).then(() => {
+      handleSubmit()
+    }).catch((error) => {
+    })
+  }
   if (option && option.id) getDetailById(option.id)
 })
 </script>

+ 19 - 0
src/pages/assistant/index.vue

@@ -42,6 +42,9 @@
               {{ `添加方式: ${getLabel(item.addType, typeList)}` }}
             </view>
           </view>
+          <view class="opt" @click.stop="showShare(item)">
+            <wd-button type="icon" icon="share" open-type="share"></wd-button>
+          </view>
           <view class="opt" @click.stop="showActions(item)">
             <wd-button type="icon" icon="more"></wd-button>
           </view>
@@ -75,6 +78,7 @@ import { getUserHubPage, deleteUserHub, testByIP } from '@/service/api'
 import { getLabel } from '@/utils'
 import { debounce } from 'wot-design-uni/components/common/util'
 
+const deviceImgSrc = ref('/static/images/device.png')
 const message = useMessage()
 const toast = useToast()
 const total = ref(0)
@@ -110,6 +114,7 @@ function buildCurrentActions() {
     { name: '查看' },
     { name: '编辑' },
     { name: '查看打印机' },
+    // { name: '分享打印助手' },
     { name: '删除', color: '#fa4350' }
   ]
 }
@@ -202,6 +207,10 @@ function toPrinter() {
   })
 }
 
+function showShare(data: any) {
+  currentData.value = data || {}
+}
+
 function showActions(data: any) {
   actionsTitle.value = data.asname ? `打印助手: ${data.asname}` : '操作'
   currentData.value = data || {}
@@ -220,6 +229,8 @@ function selectActions(data: any) {
     case '查看打印机':
       toPrinter()
       break;
+    case '分享打印助手':
+      break;
     case '删除':
       handleDelete()
       break
@@ -265,6 +276,14 @@ onReachBottom(() => {
     loadStatus.value = 'finished'
   }
 })
+
+onShareAppMessage(() => {
+  return {
+    title: "分享设备:给你分享了一个打印助手,可点击添加",
+    path: `pages/assistant/detail?type=add&hostname=${currentData.value.hostname}&asname=${currentData.value.asname}`,
+    imageUrl: deviceImgSrc.value,
+  }
+})
 </script>
 
 <style lang="scss" scoped>

+ 25 - 13
src/pages/index/index.vue

@@ -29,13 +29,13 @@
       <!-- 功能区 -->
       <view class="guide-box shadow-class">
         <view class="guide-item" @click="toUserHub('')">
-          <wd-img :src="deviceImgSrc" width="100" mode="widthFix"></wd-img>
+          <wd-img :src="deviceImgSrc" width="90" mode="widthFix"></wd-img>
           <view class="item-title">打印助手</view>
           <view class="item-desc">我的打印助手</view>
         </view>
         <view class="guide-item" @click="openWebView()">
-          <wd-img :src="fileImgSrc" width="100" mode="widthFix"></wd-img>
-          <view class="item-title">远程打印</view>
+          <wd-img :src="fileImgSrc" width="90" mode="widthFix"></wd-img>
+          <view class="item-title">手机文件</view>
           <view class="item-desc">无需驱动 隔空打印</view>
         </view>
       </view>
@@ -44,7 +44,7 @@
         <view class="section">
           <view class="item">
             <view class="title" @click="toPrint('wxImg')">
-              <wd-img :src="wechatFileSrc" width="40" mode="widthFix"></wd-img>
+              <wd-img :src="wechatImageSrc" width="40" mode="widthFix"></wd-img>
               <view class="title-text">微信图片</view>
             </view>
           </view>
@@ -117,18 +117,30 @@ const nvConfig = ref({
     initColor: '#000000',
   },
 })
-const logoSrc = ref('/static/images/logo_temp.png')
-const deviceImgSrc = ref('/static/images/device.png')
-const fileImgSrc = ref('/static/images/file.png')
-const connectSrc = ref('/static/images/connect.png')
-const pictureSrc = ref('/static/images/picture.png')
-const wechatFileSrc = ref('/static/images/wechat_file.png')
-const wechatInvoiceSrc = ref('/static/images/wechat_invoice.png')
-const historySrc = ref('/static/images/history.png')
-const shareSrc = ref('/static/images/share.png')
 const swiperList = ref([])
 const current = ref(0)
 
+const logoSrc = ref('/static/images/logo_temp1.png')
+// const deviceImgSrc = ref('/static/images/device.png')
+// const fileImgSrc = ref('/static/images/file.png')
+// const connectSrc = ref('/static/images/connect.png')
+// const pictureSrc = ref('/static/images/picture.png')
+// const wechatImageSrc = ref('/static/images/wechat_file.png')
+// const wechatFileSrc = ref('/static/images/wechatFile.png')
+// const wechatInvoiceSrc = ref('/static/images/wechat_invoice.png')
+// const historySrc = ref('/static/images/history.png')
+// const shareSrc = ref('/static/images/share.png')
+
+const deviceImgSrc = ref('/static/images/icon/printer-two.png')
+const fileImgSrc = ref('/static/images/icon/folder-open.png')
+const connectSrc = ref('/static/images/icon/connect.png')
+const pictureSrc = ref('/static/images/icon/album.png')
+const wechatImageSrc = ref('/static/images/icon/picture.png')
+const wechatFileSrc = ref('/static/images/icon/file.png')
+const wechatInvoiceSrc = ref('/static/images/icon/cards.png')
+const historySrc = ref('/static/images/icon/history-query.png')
+const shareSrc = ref('/static/images/icon/wechat.png')
+
 // 初始化 swiperList 数组
 function initSwiperList() {
   swiperList.value = [

+ 4 - 1
src/pages/login/index.vue

@@ -81,8 +81,11 @@ function handleToken(token) {
     toast.success("登录成功")
     useUserStore().setToken(token)
     useUserStore().initUserInfo()
+    const redirectPath = uni.getStorageSync("redirectPath")
+    uni.setStorageSync("redirectPath", "")
     uni.reLaunch({
-      url: `/pages/index/index`,
+      // 检查是否有重定向页面, 没有则到首页
+      url: redirectPath || `/pages/index/index`,
     })
   } else {
     handleTokenError()

+ 40 - 10
src/pages/print/index.vue

@@ -110,10 +110,10 @@
                             shape="dot"
                             inline>
               <wd-radio value="all">所有页</wd-radio>
-              <wd-radio v-if="fileList.length == 1" value="range">输入范围</wd-radio>
+              <wd-radio v-if="fileList.length == 1 && !isImg()" value="range">输入范围</wd-radio>
             </wd-radio-group>
-            <!-- 2. 当上传单个文件且radio选择 range 时允许输入范围, 从 XXX 到 XXX) -->
-            <view v-if="formData[option.key] == 'range'" style="text-align: left; margin-top: 10px">
+            <!-- 2. 当上传单个文件(非图片)且radio选择 range 时允许输入范围, 从 XXX 到 XXX) -->
+            <view v-if="!isImg() && formData[option.key] == 'range'" style="text-align: left; margin-top: 10px">
               <view class="inline-txt" style="margin-left: 0">从</view>
               <wd-input
                 custom-style="display: inline-block; width: 70px; vertical-align: middle"
@@ -268,6 +268,7 @@ function getPrinterList() {
   getUserHubPrints(params)
     .then((res: any) => {
       if (res.code === 0 && res.body) {
+        // printerList.value = res.body && res.body.length > 0 ? res.body.filter(i => i['printer-type'] == 'normal' ) : []
         printerList.value = res.body || []
         printerList.value.forEach(item => {
           item.showName = `${item.name} (${item.userHubName})`
@@ -490,6 +491,11 @@ function selectFile() {
   }
 }
 
+// 判断是否选图片, 或者选一个文件 并且图片类型 ['png', 'jpg', 'jpeg', 'gif', 'webp']
+function isImg() {
+  return accept.value == "image" || (fileList.value.length == 1 && ['png', 'jpg', 'jpeg', 'gif', 'webp'].includes(getFileType(fileList.value[0].name)))
+}
+
 // 处理文件列表增减
 function handleFileListChange() {
   // 处理打印选项参数
@@ -526,7 +532,7 @@ function downloadFile(fileName, fileUrl) {
 // 预览文件 (区分文件&图片)
 function previewFile(fileName, filePath) {
   let fileType = getFileType(fileName)
-  if (['png', 'jpg', 'jpeg', 'webp'].includes(fileType)) {
+  if (['png', 'jpg', 'jpeg', 'gif', 'webp'].includes(fileType)) {
     // 图片预览
     let imgUrl = filePath
     uni.previewImage({
@@ -710,12 +716,36 @@ function handleSubmit() {
     toast.warning('请先上传文件')
     return
   }
-  // 校验打印机属性 范围最小最小 option.min option.max
-  // for (let item of printerOptions.value) {
-  //   if (item.type == 'rang') {
-  //     if ()
-  //   }
-  // }
+  // 校验打印机属性 范围最小最大 item.min item.max
+  for (let item of printerOptions.value) {
+    if (item.type == 'rang' && formData.value[item.key] == "range") {
+      let strValue = formData.value[item.key + "_str"]
+      let endValue = formData.value[item.key + "_end"]
+      if (!strValue) {
+        toast.warning(`请输入${item.text}起始页`)
+        return
+      } else if (item.min && strValue < item.min) {
+        toast.warning(`${item.text} 起始页的最小值为${item.min}`)
+        return
+      } else if (item.max && strValue > item.max) {
+        toast.warning(`${item.text} 起始页的最大值为${item.max}`)
+        return
+      }
+      if (!endValue) {
+        toast.warning(`请输入${item.text}结束页`)
+        return
+      } else if (item.min && endValue < item.min) {
+        toast.warning(`${item.text} 结束页的最小值为${item.min}`)
+        return
+      } else if (item.max && endValue > item.max) {
+        toast.warning(`${item.text} 结束页的最大值为${item.max}`)
+        return
+      } else if (strValue && endValue < strValue) {
+        toast.warning(`${item.text} 结束页不能小于起始页`)
+        return
+      }
+    }
+  }
   form.value.validate().then(({ valid }) => {
     if (valid) {
       // 不区分单个/批量, 以批量打印处理

+ 2 - 0
src/pages/print/jobForIntranet.vue

@@ -181,12 +181,14 @@ function getIntranet() {
       getDataList(uri.value)
     } else {
       message.alert(`暂未找到该打印机:${queryParams.printer}`)
+      loadStatus.value = 'finished'
     }
   }).catch(() => {})
 }
 
 // 获取列表数据 (进行中展示全部, 历史任务前端分页)
 function getDataList(uri) {
+  if (!uri) return
   switch (queryParams.completed) {
     case "0":
       // 进行中任务

BIN
src/static/images/icon/album.png


BIN
src/static/images/icon/cards.png


BIN
src/static/images/icon/connect.png


BIN
src/static/images/icon/file.png


BIN
src/static/images/icon/folder-close.png


BIN
src/static/images/icon/folder-open.png


BIN
src/static/images/icon/history-query.png


BIN
src/static/images/icon/message.png


BIN
src/static/images/icon/picture.png


BIN
src/static/images/icon/printer-two.png


BIN
src/static/images/icon/printer.png


BIN
src/static/images/icon/wechat.png


BIN
src/static/images/logo_temp.png


BIN
src/static/images/logo_temp1.png


BIN
src/static/images/printer.jpg


BIN
src/static/images/wechatFile.png


BIN
src/static/tabbar/home.png


BIN
src/static/tabbar/homeHL.png


BIN
src/static/tabbar/order.png


BIN
src/static/tabbar/orderHL.png


BIN
src/static/tabbar/personal.png


BIN
src/static/tabbar/personalHL.png


+ 3 - 2
src/style/index.scss

@@ -14,7 +14,8 @@ page {
   background-color: #f1f1f1;
 
   // 修改主题色
-  --wot-color-theme: #FF8D1A;
+  // --wot-color-theme: #FF8D1A;
+  --wot-color-theme: #1487f4;
   --wot-color-success: #34d19d;
   --wot-color-waring: #f0883a;
   --wot-color-danger: #fa4350;
@@ -24,7 +25,7 @@ page {
   // --wot-button-primary-bg-color: #FF8D1A;
 
   // 日历选中激活颜色
-  --wot-calendar-active-color: #FF8D1A;
+  // --wot-calendar-active-color: #FF8D1A;
 }
 
 // 全屏loading

+ 26 - 12
src/utils/http.ts

@@ -1,5 +1,6 @@
 import { CustomRequestOptions } from '@/interceptors/request'
 import { useUserStore } from '@/store'
+import { currRoute, currFullPath } from "@/utils"
 
 export const http = <T>(options: CustomRequestOptions) => {
   // 1. 返回 Promise 对象
@@ -12,21 +13,34 @@ export const http = <T>(options: CustomRequestOptions) => {
       // #endif
       // 响应成功
       success(res) {
-        // 状态码 2xx,参考 axios 的设计
+        // console.log("options.url:", options.url);
+        // console.log("currRoute:", currRoute());
+        // console.log("currFullPath:", currFullPath());
+        // 状态码 2xx
         if (res.statusCode >= 200 && res.statusCode < 300) {
-          // 2.1 提取核心数据 res.data
+          // 特殊处理(非登录页 && 使用自动登录异常)
+          if (options.url == "/api/wx/mini/login" && currRoute().path != "/pages/login/index" && res.statusCode == 200 && res.data.body.res == '1') {
+            uni.setStorageSync("redirectPath", currFullPath())
+            reject(res)
+          }
+          // 提取核心数据 res.data
           resolve(res.data as IResData<T>)
         } else if (res.statusCode === 401) {
-          // // 401错误 -> 清理用户信息,跳转到登录页
-          // useUserStore().clearUserInfo()
-          // uni.reLaunch({ url: '/pages/login/index?isLogout=1' })
-          // reject(res)
-
-          // 401错误 -> 自动刷新token
-          useUserStore().wxLogin().then((token) => {
-            temp.header['X-ACCESS-TOKEN'] = token
-            uni.request(temp)
-          })
+          if (options.url == "/api/wx/mini/login") {
+            // 401错误(登录接口) -> 清理用户信息,跳转到登录页
+            uni.setStorageSync("redirectPath", currFullPath())
+            useUserStore().clearUserInfo()
+            uni.reLaunch({ url: '/pages/login/index?isLogout=1' })
+            reject(res)
+          } else {
+            // 401错误(非登录接口) -> 自动刷新token
+            useUserStore().wxLogin().then((token) => {
+              temp.header['X-ACCESS-TOKEN'] = token
+              uni.request(temp)
+            }).catch(() => {
+              reject(res)
+            })
+          }
         } else {
           // 其他错误 -> 根据后端错误信息轻提示
           !options.hideErrorToast &&

+ 7 - 0
src/utils/index.ts

@@ -43,6 +43,13 @@ export const currRoute = () => {
   return getUrlObj(fullPath)
 }
 
+export const currFullPath = () => {
+  const lastPage = getLastPage()
+  const currRoute = (lastPage as any).$page
+  const { fullPath } = currRoute as { fullPath: string }
+  return fullPath
+}
+
 const ensureDecodeURIComponent = (url: string) => {
   if (url.startsWith('%')) {
     return ensureDecodeURIComponent(decodeURIComponent(url))