ソースを参照

语音播报金额 mixin

zhengxin 5 年 前
コミット
314223680f
4 ファイル変更228 行追加67 行削除
  1. 46 43
      ghs/babel.config.js
  2. 15 12
      ghs/src/admin/billing/index.vue
  3. 152 0
      ghs/src/mixins/priceAudio.js
  4. 15 12
      ghs/src/pagesOrder/select.vue

+ 46 - 43
ghs/babel.config.js

@@ -1,54 +1,57 @@
-const plugins = []
+const plugins = [];
 
 if (process.env.UNI_OPT_TREESHAKINGNG) {
-  plugins.push(require('@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js'))
+	plugins.push(
+		require("@dcloudio/vue-cli-plugin-uni-optimize/packages/babel-plugin-uni-api/index.js")
+	);
 }
 
-if (process.env.UNI_PLATFORM === 'app-plus' && process.env.UNI_USING_V8) {
-  const path = require('path')
+if (process.env.UNI_PLATFORM === "app-plus" && process.env.UNI_USING_V8) {
+	const path = require("path");
 
-  const isWin = /^win/.test(process.platform)
+	const isWin = /^win/.test(process.platform);
 
-  const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
+	const normalizePath = path => (isWin ? path.replace(/\\/g, "/") : path);
 
-  const input = normalizePath(process.env.UNI_INPUT_DIR)
-  try {
-    plugins.push([
-      require('@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console'),
-      {
-        file (file) {
-          file = normalizePath(file)
-          if (file.indexOf(input) === 0) {
-            return path.relative(input, file)
-          }
-          return false
-        }
-      }
-    ])
-  } catch (e) {}
+	const input = normalizePath(process.env.UNI_INPUT_DIR);
+	try {
+		plugins.push([
+			require("@dcloudio/vue-cli-plugin-hbuilderx/packages/babel-plugin-console"),
+			{
+				file(file) {
+					file = normalizePath(file);
+					if (file.indexOf(input) === 0) {
+						return path.relative(input, file);
+					}
+					return false;
+				}
+			}
+		]);
+	} catch (e) {}
 }
 
-process.UNI_LIBRARIES = process.UNI_LIBRARIES || ['@dcloudio/uni-ui']
+process.UNI_LIBRARIES = process.UNI_LIBRARIES || ["@dcloudio/uni-ui"];
 process.UNI_LIBRARIES.forEach(libraryName => {
-  plugins.push([
-    'import',
-    {
-      'libraryName': libraryName,
-      'customName': (name) => {
-        return `${libraryName}/lib/${name}/${name}`
-      }
-    }
-  ])
-})
+	plugins.push([
+		"import",
+		{
+			libraryName: libraryName,
+			customName: name => {
+				return `${libraryName}/lib/${name}/${name}`;
+			}
+		}
+	]);
+});
 module.exports = {
-  presets: [
-    [
-      '@vue/app',
-      {
-        modules: 'commonjs',
-        useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry'
-      }
-    ]
-  ],
-  plugins
-}
+	presets: [
+		[
+			"@vue/app",
+			{
+				modules: "commonjs",
+				useBuiltIns: process.env.UNI_PLATFORM === "h5" ? "usage" : "entry"
+			}
+		]
+	],
+	ignore: ["./src/pagesOrder/js/**/*.js"],
+	plugins
+};

+ 15 - 12
ghs/src/admin/billing/index.vue

@@ -72,20 +72,23 @@
 							{{ classItem.className }}
 						</view>
 						<template v-for="(productItem, productIndex) in classItem.child">
-							<Commondity
+							<view
 								:id="`class_${classItem.classId}_${productItem.id}`"
 								:key="productIndex"
-								:info="productItem"
-								:bigCount="
-									getSelectItemById(productItem.id, classItem.classId).bigCount
-								"
-								:smallCount="
-									getSelectItemById(productItem.id, classItem.classId).smallCount
-								"
-								@customNum="customNum"
-								@add="addEvent"
-								@del="delEvent"
-							></Commondity>
+							>
+								<Commondity
+									:info="productItem"
+									:bigCount="
+										getSelectItemById(productItem.id, classItem.classId).bigCount
+									"
+									:smallCount="
+										getSelectItemById(productItem.id, classItem.classId).smallCount
+									"
+									@customNum="customNum"
+									@add="addEvent"
+									@del="delEvent"
+								></Commondity>
+							</view>
 							<!-- <Commondity
 							:type="COMMODITY_TYPE.CHANGE"
 							@customNum="customNum"

+ 152 - 0
ghs/src/mixins/priceAudio.js

@@ -0,0 +1,152 @@
+/**
+ *示例
+ * this.playPriceAudio(123.32);
+ */
+
+export default {
+	onLunch() {},
+	data() {
+		return {
+			playing: false,
+			priceHanderList: []
+		};
+	},
+	methods: {
+		playPriceAudio(price) {
+			this.priceHanderList.push(() => {
+				return new Promise((resolve, reject) => {
+					this.formatPriceAudio(price)
+						.then(res => {
+							resolve(res);
+						})
+						.catch(err => {
+							reject(err);
+						});
+				});
+			});
+			if (this.playing) {
+			} else {
+				this.playAllPriceAudio();
+			}
+		},
+		async playAllPriceAudio() {
+			try {
+				this.playing = true;
+				await this.formatAudioPromise(this.priceHanderList);
+
+				this.playing = false;
+				return true;
+			} catch (error) {
+				this.playing = false;
+			}
+		},
+
+		getPriceAutioSrcByType(type) {
+			let src = `${this.$constant.imgUrl}/audio/${type}.wav`;
+
+			return src;
+		},
+		async formatPriceAudio(num) {
+			let priceHandler = [];
+			let count = String(num);
+			let countList = count.split(".");
+			let intNum = countList[0];
+			let floatNum = countList[1];
+
+			if (intNum >= 0) {
+				let priceList = [];
+				for (const item of intNum) {
+					priceList.push(item);
+				}
+				let individual = priceList.pop();
+				if (individual) {
+					priceHandler.unshift(this.createPlayHandler(individual));
+					let ten = priceList.pop();
+					if (ten) {
+						priceHandler.unshift(this.createPlayHandler("shi"));
+						priceHandler.unshift(this.createPlayHandler(ten));
+
+						let hundred = priceList.pop();
+						if (hundred) {
+							priceHandler.unshift(this.createPlayHandler("bai"));
+							priceHandler.unshift(this.createPlayHandler(hundred));
+
+							let thousand = priceList.pop();
+							if (thousand) {
+								priceHandler.unshift(this.createPlayHandler("qian"));
+								priceHandler.unshift(this.createPlayHandler(thousand));
+
+								if (priceList.length > 0) {
+									priceHandler.unshift(this.createPlayHandler("wan"));
+									for (const item of priceList) {
+										priceList = [this.createPlayHandler(item)].concat(priceList);
+									}
+								}
+							}
+						}
+					}
+				} else {
+					if (floatNum >= 0) {
+						priceHandler.unshift(this.createPlayHandler("0"));
+					}
+				}
+			}
+
+			if (floatNum >= 0) {
+				priceHandler.push(this.createPlayHandler("."));
+				for (const item of floatNum) {
+					priceHandler.push(this.createPlayHandler(item));
+				}
+			}
+			priceHandler.push(this.createPlayHandler("yuan"));
+			priceHandler.unshift(this.createPlayHandler("ccb"));
+
+			const outBack = async () => {
+				return new Promise(resolve => {
+					setTimeout(function() {
+						resolve();
+					}, 500);
+				});
+			};
+			priceHandler.push(outBack);
+
+			return this.formatAudioPromise(priceHandler);
+		},
+		async formatAudioPromise(handlerList) {
+			try {
+				const handlerItem = handlerList.shift();
+				if (handlerItem) {
+					await handlerItem();
+					if (handlerList.length > 0) {
+						return this.formatAudioPromise(handlerList);
+					}
+				}
+				return true;
+			} catch (error) {
+				return Promise.reject(error);
+			}
+		},
+		createPlayHandler(type) {
+			return () => {
+				return new Promise((resolve, reject) => {
+					const innerAudioContext = uni.createInnerAudioContext();
+					innerAudioContext.autoplay = true;
+					innerAudioContext.src = this.getPriceAutioSrcByType(type);
+					innerAudioContext.onPlay(() => {
+						console.log("开始播放", type);
+					});
+					innerAudioContext.onError(res => {
+						console.log(res.errMsg);
+						console.log(res.errCode);
+						reject(res);
+					});
+					innerAudioContext.onEnded(err => {
+						console.log("开始结束", type);
+						innerAudioContext.destroy();
+						resolve(err);
+					});
+				});
+			};
+		}
+	}
+};

+ 15 - 12
ghs/src/pagesOrder/select.vue

@@ -72,20 +72,23 @@
 							{{ classItem.className }}
 						</view>
 						<template v-for="(productItem, productIndex) in classItem.child">
-							<Commondity
+							<view
 								:id="`class_${classItem.classId}_${productItem.id}`"
 								:key="productIndex"
-								:info="productItem"
-								:bigCount="
-									getSelectItemById(productItem.id, classItem.classId).bigCount
-								"
-								:smallCount="
-									getSelectItemById(productItem.id, classItem.classId).smallCount
-								"
-								@customNum="customNum"
-								@add="addEvent"
-								@del="delEvent"
-							></Commondity>
+							>
+								<Commondity
+									:info="productItem"
+									:bigCount="
+										getSelectItemById(productItem.id, classItem.classId).bigCount
+									"
+									:smallCount="
+										getSelectItemById(productItem.id, classItem.classId).smallCount
+									"
+									@customNum="customNum"
+									@add="addEvent"
+									@del="delEvent"
+								></Commondity>
+							</view>
 							<!-- <Commondity
 							:type="COMMODITY_TYPE.CHANGE"
 							@customNum="customNum"