Преглед на файлове

推送相关代码提交

yangzm123 преди 1 година
родител
ревизия
c808c8544e

+ 4 - 4
src/App.vue

@@ -9,10 +9,10 @@
 export default {
     onLaunch: function () {
         console.log("App Launch");
-        uni.onPushMessage(res => {
-            console.log("收到推送消息:", res); //监听推送消息
-            uni.$uv.toast("收到推送消息");
-        });
+        // uni.onPushMessage(res => {
+            // console.log("收到推送消息:", res); //监听推送消息
+            // uni.$uv.toast("收到推送消息");
+        // });
     },
     onShow: function () {
         console.log("App Show");

+ 4 - 1
src/config/apis/auth.js

@@ -2,7 +2,7 @@
  * @Author: PoJun
  * @Date: 2023-09-13 17:12:51
  * @LastEditors: PoJun
- * @LastEditTime: 2024-01-04 16:42:03
+ * @LastEditTime: 2024-01-18 11:12:36
  * @Message: 登录相关
  */
 const { http } = uni.$uv;
@@ -31,3 +31,6 @@ export const supplierAffair = (data, config) => http.post("/affair_ext/SupplierA
 
 // 注销账号
 export const cancelUser = data => http.post("/web/cancel", data);
+
+// 更新用户的uniapp客户端Id
+export const updateClientInfo = data => http.post("/system_ext/user/client_info", data);

+ 13 - 0
src/config/apis/products.js

@@ -0,0 +1,13 @@
+/*
+ * @Author: PoJun
+ * @Date: 2023-09-13 17:12:51
+ * @LastEditors: PoJun
+ * @LastEditTime: 2024-01-18 14:24:43
+ * @Message: 产品相关
+ */
+const { http } = uni.$uv;
+/** 获取无权限产品目录树 */
+export const getProductsTreeNoAuth = () => http.get(`/product_dirs/tree_noauth`);
+
+/** 产品目录对应的供应商数量 */
+export const getHomeChartData = () => http.get(`/product_dirs/supplierCountGroupByProduct`);

+ 1 - 0
src/config/http.js

@@ -10,3 +10,4 @@ export * from "./apis/dict";
 export * from "./apis/supplier";
 export * from "./apis/message";
 export * from "./apis/flow";
+export * from "./apis/products";

+ 41 - 28
src/pages/index/components/home-chart.vue

@@ -2,18 +2,25 @@
  * @Author: PoJun
  * @Date: 2023-12-19 14:57:48
  * @LastEditors: PoJun
- * @LastEditTime: 2024-01-04 17:34:18
+ * @LastEditTime: 2024-01-18 14:44:19
  * @Message: 柱形图
 -->
 <template>
     <view class="data-charts">
         <view class="uv-font-md uv-weight-700 uv-m-25">产品-供应商数量</view>
-        <qiun-data-charts type="column" :opts="opts" :chartData="chartData" />
+        <qiun-data-charts type="column" :ontouch="true" :opts="opts" :chartData="chartData" />
     </view>
 </template>
 
 <script>
+import { getHomeChartData } from "@/config/http.js";
 export default {
+    props: {
+        times: {
+            type: Number,
+            default: 0,
+        },
+    },
     data() {
         return {
             chartData: {},
@@ -21,11 +28,14 @@ export default {
                 padding: [15, 15, 5, 15],
                 fontSize: 12,
                 touchMoveLimit: 24,
-                enableScroll: false,
+                enableScroll: true,
+                legend: {
+                    show: false,
+                },
                 xAxis: {
                     disableGrid: true,
-                    scrollShow: true,
-                    itemCount: 4,
+                    scrollShow: false,
+                    itemCount: 5,
                 },
                 yAxis: {
                     data: [
@@ -33,6 +43,8 @@ export default {
                             min: 0,
                         },
                     ],
+                    splitNumber: 5,
+                    disableGrid: true,
                 },
                 extra: {
                     column: {
@@ -46,31 +58,32 @@ export default {
         };
     },
     methods: {
-        getServerData() {
-            //模拟从服务器获取数据时的延时
-            setTimeout(() => {
-                //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
-                let res = {
-                    categories: ["原材料", "工程材料", "资产"],
-                    series: [
-                        {
-                            name: "产品",
-                            data: [3, 8, 11],
-                        },
-                        {
-                            name: "供应商",
-                            data: [12, 11, 21],
-                        },
-                    ],
-                };
-                this.chartData = JSON.parse(JSON.stringify(res));
-            }, 500);
+        async init() {
+            try {
+                const data = await getHomeChartData();
+                const categories = data.map(item => item.name);
+                const series = [
+                    {
+                        name: "供应商数量",
+                        data: data.map(item => item.c),
+                    },
+                ];
+
+                this.$nextTick(() => {
+                    this.chartData = JSON.parse(JSON.stringify({ categories, series }));
+                });
+            } catch (error) {
+                console.log(error);
+            }
         },
     },
-    mounted() {
-        this.$nextTick(() => {
-            this.getServerData();
-        });
+    watch: {
+        times: {
+            immediate: true,
+            handler: function () {
+                this.init();
+            },
+        },
     },
 };
 </script>

+ 54 - 16
src/pages/index/components/products-list.vue

@@ -2,7 +2,7 @@
  * @Author: PoJun
  * @Date: 2023-12-19 14:57:48
  * @LastEditors: PoJun
- * @LastEditTime: 2023-12-26 11:17:27
+ * @LastEditTime: 2024-01-18 10:53:10
  * @Message: 产品列表, 只展示5个
 -->
 <template>
@@ -11,30 +11,68 @@
             <uv-text slot="title" text="产品目录" :customStyle="{ 'font-weight': 'bold' }"></uv-text>
         </uv-cell>
 
-        <uv-cell
-            v-for="(item, index) in productsList"
-            :key="index"
-            :border="false"
-            :label="item.code"
-            :value="item.name"
-        ></uv-cell>
+        <template v-if="productsList.length">
+            <uv-cell
+                v-for="(item, index) in productsList"
+                :key="index"
+                :border="false"
+                :label="item.code"
+                :value="item.name"
+            ></uv-cell>
+        </template>
+
+        <view v-else class="uv-m-b-50">
+            <uv-empty marginTop="30" mode="data" text="暂无数据"></uv-empty>
+        </view>
     </uv-cell-group>
 </template>
 
 <script>
+import { getProductsTreeNoAuth } from "@/config/http.js";
 export default {
     data() {
         return {
-            productsList: [
-                { name: "原材料-化工类", code: "1000101", id: "1111" },
-                { name: "原材料-建筑结构类", code: "1000102", id: "2222" },
-                { name: "原材料-型材类", code: "1000103", id: "3333" },
-                { name: "工程材料-管道及配件", code: "1000104", id: "4444" },
-                { name: "工程材料-风管机配件类", code: "1000105", id: "5555" },
-            ],
+            productsList: [],
         };
     },
-    methods: {},
+    methods: {
+        // 获取产品目录, 缓存下后续直接用
+        async getList() {
+            try {
+                const data = await getProductsTreeNoAuth();
+                this.$uv.vuex("vuex_products", data ? data : []);
+                this.resetData(data);
+            } catch (error) {
+                console.log(error);
+            }
+        },
+        // 展开下数组处理数据,选个大概5条?
+        resetData(data = []) {
+            try {
+                this.productsList = this.treeToArray(JSON.parse(JSON.stringify(data))).slice(0, 5);
+            } catch (error) {
+                console.log(error);
+            }
+        },
+        treeToArray(list, newArr = []) {
+            list.forEach(item => {
+                const { children } = item;
+                if (children) {
+                    delete item.children;
+
+                    if (children.length) {
+                        newArr.push(item);
+                        return this.treeToArray(children, newArr);
+                    }
+                }
+                newArr.push(item);
+            });
+            return newArr;
+        },
+    },
+    created() {
+        this.getList();
+    },
 };
 </script>
 

+ 6 - 34
src/pages/index/index.vue

@@ -2,7 +2,7 @@
  * @Author: PoJun
  * @Date: 2023-05-15 19:59:55
  * @LastEditors: PoJun
- * @LastEditTime: 2024-01-09 16:19:14
+ * @LastEditTime: 2024-01-18 14:25:57
  * @Message: Nothing
 -->
 <template>
@@ -23,7 +23,7 @@
                 </view>
                 <!-- 统计图 -->
                 <view class="content-container">
-                    <home-chart></home-chart>
+                    <home-chart :times="times"></home-chart>
                 </view>
             </view>
             <!-- 供应商角色 -->
@@ -51,12 +51,6 @@
                 shape="circle"
             ></uv-button>
         </no-auth>
-
-        <uv-textarea
-            :value="iinfo"
-            :autoHeight="true"
-            :textStyle="{ fontSize: '14px', textAlign: 'right' }"
-        ></uv-textarea>
     </view>
 </template>
 
@@ -80,9 +74,12 @@ export default {
     data() {
         return {
             BannerImg,
-            iinfo: null,
+            times: 0, //图形的渲染有时候会出问题.
         };
     },
+    onShow() {
+        this.times++;
+    },
     methods: {
         toLogin() {
             if (!this.vuex_userInfo) {
@@ -90,33 +87,8 @@ export default {
             } else {
                 uni.$uv.route("/subpkg/setting/authentication");
             }
-
-            // 主动创建通知栏在线消息
-            // uni.createPushMessage({
-            //     title: "消息通知",
-            //     content: "下午开个小会",
-            //     success: () => {
-            //         console.log("success");
-            //     },
-            //     fail: () => {
-            //         console.log("fail");
-            //     },
-            // });
         },
     },
-    computed: {},
-    onLoad() {},
-    onShow() {},
-    onReady() {
-        setTimeout(() => {
-            plus.push.getClientInfoAsync(info => {
-                console.log(info);
-                console.log(info);
-                console.log(info);
-                this.iinfo = JSON.stringify(info);
-            });
-        }, 2000);
-    },
 };
 </script>
 

+ 17 - 5
src/pages/login/index.vue

@@ -2,7 +2,7 @@
  * @Author: PoJun
  * @Date: 2023-09-28 10:38:11
  * @LastEditors: PoJun
- * @LastEditTime: 2024-01-08 10:20:32
+ * @LastEditTime: 2024-01-18 11:16:22
  * @Message: 登录页面
 -->
 <template>
@@ -68,7 +68,7 @@
 </template>
 
 <script>
-import { wechatLogin } from "@/config/http.js";
+import { wechatLogin, updateClientInfo } from "@/config/http.js";
 import LoginGg from "@/static/login_bg.png";
 
 export default {
@@ -80,9 +80,19 @@ export default {
             },
             checkboxValue: [],
             LoginGg,
+            clientInfo: null,
         };
     },
-    onLoad() {},
+    onLoad() {
+        // #ifdef APP-PLUS
+        setTimeout(() => {
+            // 设备信息
+            plus.push.getClientInfoAsync(info => {
+                this.clientInfo = info;
+            });
+        }, 100);
+        // #endif
+    },
     methods: {
         check(type) {
             uni.$uv.route({
@@ -99,8 +109,10 @@ export default {
             const data = await wechatLogin(this.auth.name, this.auth.password, "Password");
             uni.setStorageSync("vuex_token", data.token);
             this.$store.commit("$updateLoginInfo", data);
-            await uni.$uv.sleep(100);
-            // await this.$store.dispatch("UPDATELOGININFO");
+            // #ifdef APP-PLUS
+            await updateClientInfo(this.clientInfo.clientid);
+            // #endif
+            await uni.$uv.sleep(10);
             try {
                 uni.$uv.route({ type: "back" });
             } finally {

+ 2 - 1
src/store/index.js

@@ -2,7 +2,7 @@
  * @Author: PoJun
  * @Date: 2023-05-14 17:52:10
  * @LastEditors: PoJun
- * @LastEditTime: 2024-01-04 15:25:49
+ * @LastEditTime: 2024-01-18 10:37:37
  * @Message: Nothing
  */
 import Vue from "vue";
@@ -41,6 +41,7 @@ const store = new Vuex.Store({
         // 人员信息展开, 在使用的时候方便使用, 使用null是为了在未登录情况小程序端不出现undefined
         vuex_userInfo: lifeData.vuex_userInfo ? lifeData.vuex_userInfo : null, //登录信息
         vuex_affairNum: 0,
+        vuex_products: [], //产品目录
     },
     mutations: {
         $uStore(state, payload) {

+ 3 - 1
src/subpkg/flow/detail.vue

@@ -2,7 +2,7 @@
  * @Author: PoJun
  * @Date: 2024-01-03 16:13:54
  * @LastEditors: PoJun
- * @LastEditTime: 2024-01-04 17:33:34
+ * @LastEditTime: 2024-01-18 15:08:08
  * @Message: Nothing
 -->
 <template>
@@ -120,10 +120,12 @@ export default {
             });
         },
         async refuse() {
+            uni.showLoading({ mask: true });
             await refuseAffairs(this.id);
             this.doback();
         },
         async agree() {
+            uni.showLoading({ mask: true });
             await agreeAffairs(this.id, this.detailItem.data);
             this.doback();
         },

+ 13 - 179
src/subpkg/home/products.vue

@@ -2,27 +2,27 @@
  * @Author: PoJun
  * @Date: 2023-09-28 10:38:11
  * @LastEditors: PoJun
- * @LastEditTime: 2023-12-21 14:24:01
+ * @LastEditTime: 2024-01-18 11:10:00
  * @Message: 产品列表
 -->
 <template>
     <view class="products">
-        <uv-vtabs :chain="true" :list="list" :height="height" @change="change">
-            <template v-for="(item, index) in list">
+        <uv-vtabs :chain="true" :list="vuex_products" :height="height" @change="change">
+            <template v-for="(item, index) in vuex_products">
                 <uv-vtabs-item :index="index" :key="index">
                     <view
                         class="products-item uv-flex uv-border-bottom"
-                        v-for="(item2, index2) in item.childrens"
+                        v-for="(item2, index2) in item.children"
                         :key="index2"
                     >
-                        <uv-image src="" width="66px" height="66px"></uv-image>
+                        <uv-image :src="getImageUrl(item2.image)" width="66px" height="66px"></uv-image>
                         <view class="uv-m-l-26 uv-flex-1">
                             <view class="uv-font-28">{{ item2.name }}</view>
-                            <view class="uv-font-26 uv-m-t-12 uv-info">{{ item2.sub }}</view>
-                            <view class="uv-font-26 uv-m-t-22 uv-info">{{ item2.desc }}</view>
+                            <view class="uv-font-26 uv-m-t-12 uv-info">{{ item2.code }}</view>
+                            <view class="uv-font-26 uv-m-t-22 uv-info">{{ item2.remark }}</view>
                         </view>
                     </view>
-                    <view v-if="index < list.length - 1">
+                    <view v-if="index < vuex_products.length - 1">
                         <uv-gap bg-color="#f1f1f1" height="5"></uv-gap>
                     </view>
                 </uv-vtabs-item>
@@ -34,168 +34,6 @@
 </template>
 
 <script>
-const getList = [
-    {
-        name: "原材料",
-        childrens: [
-            {
-                name: "化工类",
-                sub: "春晓",
-                desc: "春眠不觉晓,处处闻啼鸟。夜来风雨声,花落知多少。",
-            },
-            {
-                name: "建筑结构类",
-                desc: "碧玉妆成一树高,万条垂下绿丝绦。不知细叶谁裁出,二月春风似剪刀。",
-                sub: "咏柳",
-            },
-            {
-                name: "型材类",
-                desc: "独在异乡为异客,每逢佳节倍思亲。遥知兄弟登高处,遍插茱萸少一人。",
-                sub: "九月九日忆山东兄弟",
-            },
-        ],
-    },
-    {
-        name: "工程材料",
-        childrens: [
-            {
-                name: "管道及配件",
-                sub: "副标题",
-                desc: "一些简单的描述",
-            },
-            {
-                name: "风管机配件",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "阀门",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "保温吸音材料",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "电工电器",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "仪器仪表",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "工程设备",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "成品支吊架",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "园林景观",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-        ],
-    },
-    {
-        name: "服务",
-        childrens: [
-            {
-                name: "外包",
-                sub: "副标题",
-                desc: "一些简单的描述",
-            },
-            {
-                name: "分包",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-        ],
-    },
-    {
-        name: "资产",
-        childrens: [
-            {
-                name: "车辆",
-                sub: "副标题",
-                desc: "一些简单的描述",
-            },
-            {
-                name: "房地产",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "办公家具",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "办公电子设备",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "检测设备",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "厂房设备",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-        ],
-    },
-    {
-        name: "低值易耗品",
-        childrens: [
-            {
-                name: "施工材料",
-                sub: "副标题",
-                desc: "一些简单的描述",
-            },
-            {
-                name: "工具",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-            {
-                name: "办公生活用品",
-                desc: "一些简单的描述",
-                sub: "副标题",
-            },
-        ],
-    },
-    {
-        name: "安全消防",
-        childrens: [
-            {
-                name: "安全消防防护",
-                sub: "副标题",
-                desc: "一些简单的描述",
-            },
-            {
-                name: "安全消防防护",
-                sub: "副标题",
-                desc: "一些简单的描述",
-            },
-            {
-                name: "安全消防防护",
-                sub: "副标题",
-                desc: "一些简单的描述",
-            },
-        ],
-    },
-];
 export default {
     data() {
         return {
@@ -207,20 +45,16 @@ export default {
             return uni.getSystemInfoSync().windowHeight;
         },
     },
-    onReady() {
-        // 模拟接口请求数据
-        uni.showLoading({
-            title: "加载中",
-        });
-        setTimeout(() => {
-            this.list = getList;
-            uni.hideLoading();
-        }, 500);
+    onLoad() {
+        console.log(this.vuex_products);
     },
     methods: {
         change(index) {
             console.log("选项改变:", index);
         },
+        getImageUrl(id) {
+            return id ? process.env.VUE_APP_BASE_API + `/files/${id}/show_image` : "";
+        },
     },
 };
 </script>

+ 7 - 2
src/subpkg/setting/constant.js

@@ -2,7 +2,7 @@
  * @Author: PoJun
  * @Date: 2023-12-14 21:10:35
  * @LastEditors: PoJun
- * @LastEditTime: 2024-01-05 11:09:33
+ * @LastEditTime: 2024-01-18 10:31:36
  * @Message: Nothing
  */
 // 个人信息表单信息
@@ -98,7 +98,12 @@ export const authenticationFormList = [
         canShow: true,
         canEdit: true,
         required: true,
-        dictCode: "supplierType",
+        options: [
+            { name: "战略供应商", key: "战略供应商" },
+            { name: "瓶颈供应商", key: "瓶颈供应商" },
+            { name: "杠杆供应商", key: "杠杆供应商" },
+            { name: "一般供应商", key: "一般供应商" },
+        ],
     },
 ];
 // 修改密码

+ 16 - 8
src/utils/utils.js

@@ -2,14 +2,22 @@
  * @Author: PoJun
  * @Date: 2023-12-14 15:56:24
  * @LastEditors: PoJun
- * @LastEditTime: 2023-12-26 10:47:44
+ * @LastEditTime: 2024-01-18 14:23:34
  * @Message: Nothing
  */
-export const logoutApp = vm => {
-    uni.removeStorageSync("vuex_token");
-    uni.removeStorageSync("lifeData");
-    vm.$uv.vuex("vuex_userInfo", null);
-    uni.$uv.sleep(100).then(() => {
-        uni.$uv.route({ url: "/pages/mine/index", type: "switchTab" });
-    });
+export const logoutApp = async vm => {
+    // 退出设备
+    try {
+        // #ifdef APP-PLUS
+        await uni.$uv.http.get("/system_ext/user/client_info", { custom: { toast: false } });
+        // #endif
+        uni.removeStorageSync("vuex_token");
+        uni.removeStorageSync("lifeData");
+        vm.$uv.vuex("vuex_userInfo", null);
+        uni.$uv.sleep(100).then(() => {
+            uni.$uv.route({ url: "/pages/mine/index", type: "switchTab" });
+        });
+    } catch (error) {
+        console.log(error);
+    }
 };

+ 6 - 6
uniCloud-aliyun/cloudfunctions/pushMessage/index.js

@@ -3,15 +3,15 @@ const uniPush = uniCloud.getPushManager({
 	appId: "__UNI__82C0680"
 });
 exports.main = async (event) => {
-	let obj = JSON.parse(event.body); //这是重点 解析json字符串
+	let obj =  event.body? JSON.parse(event.body) :{}; //这是重点 解析json字符串
 	const res = await uniPush.sendMessage({
-		"push_clientid": obj.cids, // 设备id,支持多个以数组的形式指定多个设备,如["cid-1","cid-2"],数组长度不大于1000  
-		"title": obj.title, // 标题  
+		"push_clientid": obj.clientId, // 设备id,支持多个以数组的形式指定多个设备,如["cid-1","cid-2"],数组长度不大于1000  
+		"title": obj.type, // 标题  
 		"content": obj.content, // 内容  
-		"payload": obj.data, // 数据  
+		// "payload": obj.data, // 数据              // await this.$store.dispatch("UPDATELOGININFO");
 		"force_notification": true, // 服务端推送 需要加这一句  
-		"request_id": obj.request_id, //请求唯一标识号,10-32位之间;如果request_id重复,会导致消息丢失  
-		"options": obj.options //消息分类,没申请可以不传这个参数  
+		"request_id": obj.id, //请求唯一标识号,10-32位之间;如果request_id重复,会导致消息丢失  
+		// "options": obj.options //消息分类,没申请可以不传这个参数  
 	});
 	return res;
 };

+ 4 - 0
uniCloud-aliyun/cloudfunctions/pushMessage/pushMessage.param.json

@@ -0,0 +1,4 @@
+// 本文件中的json内容将在云函数【运行】时作为参数传给云函数。
+// 配置教程参考:https://uniapp.dcloud.net.cn/uniCloud/rundebug.html#runparam
+{
+}