瀏覽代碼

打印机功能新加字段

licc 3 天之前
父節點
當前提交
af68829f87
共有 3 個文件被更改,包括 290 次插入207 次删除
  1. 2 2
      src/config/index.ts
  2. 132 111
      src/views/shop/print/edit.vue
  3. 156 94
      src/views/shop/print/index.vue

+ 2 - 2
src/config/index.ts

@@ -2,8 +2,8 @@ const config = {
     terminal: 1, //终端
     title: '后台管理系统', //网站默认标题
     version: '1.4.0', //版本号
-    baseUrl: `${import.meta.env.VITE_APP_BASE_URL || 'https://gatewaytest1.elab-plus.com'}/`, //请求接口域名 http://192.168.50.19:5555/elab-marketing-file
-    urlPrefix: 'elab-marketing-file/api', //请求默认前缀
+    baseUrl: `${import.meta.env.VITE_APP_BASE_URL || 'http://192.168.50.19:5555/elab-marketing-file'}/`, //请求接口域名 http://192.168.50.19:5555/elab-marketing-file
+    urlPrefix: 'api', //请求默认前缀
     timeout: 10 * 1000 //请求超时时长
 }
 

+ 132 - 111
src/views/shop/print/edit.vue

@@ -1,147 +1,168 @@
 <template>
-    <div class="edit-popup">
-        <popup
-            ref="popupRef"
-            :title="popupTitle"
-            :async="true"
-            width="550px"
-            @confirm="handleSubmit"
-            @close="handleClose"
-        >
-            <el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
-                <el-form-item label="打印机名称" prop="name">
-                    <el-input v-model="formData.name" placeholder="请输入打印机名称" clearable />
-                </el-form-item>
-                <el-form-item label="终端号" prop="finalNumber">
-                    <el-input
-                        v-model="formData.finalNumber"
-                        placeholder="请输入打印机终端号"
-                        clearable
-                    />
-                </el-form-item>
-                <el-form-item label="打印机密钥" prop="secret">
-                    <el-input v-model="formData.secret" placeholder="请输入打印机密钥" clearable />
-                </el-form-item>
-                <el-form-item label="设备类型" prop="type">
-                    <el-select v-model="formData.type" placeholder="请选择设备类型">
-                        <el-option label="芯烨云" :value="1" />
-                    </el-select>
-                </el-form-item>
-                <el-form-item label="小票模板" prop="mode">
-                    <el-select v-model="formData.mode" placeholder="请选择打印模板">
-                        <el-option label="模板01" :value="1" />
-                    </el-select>
-                </el-form-item>
-                <!-- <el-form-item label="排序" prop="sort">
-                    <div>
-                        <el-input-number v-model="formData.sort" :min="0" :max="9999" />
-                        <div class="form-tips">默认为0, 数值越大越排前</div>
-                    </div>
-                </el-form-item> -->
-                <el-form-item label="状态" prop="status">
-                    <el-switch v-model="formData.status" :active-value="1" :inactive-value="0" />
-                </el-form-item>
-            </el-form>
-        </popup>
-    </div>
+  <div class="edit-popup">
+    <popup
+        ref="popupRef"
+        :title="popupTitle"
+        :async="true"
+        width="550px"
+        @confirm="handleSubmit"
+        @close="handleClose"
+    >
+      <el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
+        <el-form-item label="打印机名称" prop="name">
+          <el-input v-model="formData.name" placeholder="请输入打印机名称" clearable/>
+        </el-form-item>
+        <el-form-item label="终端号" prop="finalNumber">
+          <el-input
+              v-model="formData.finalNumber"
+              placeholder="请输入打印机终端号"
+              clearable
+          />
+        </el-form-item>
+        <!--                <el-form-item label="打印机密钥" prop="secret">-->
+        <!--                    <el-input v-model="formData.secret" placeholder="请输入打印机密钥" clearable />-->
+        <!--                </el-form-item>-->
+        <el-form-item label="设备类型" prop="type">
+          <el-select v-model="formData.type" placeholder="请选择设备类型" disabled>
+            <el-option label="芯烨云" :value="1"/>
+          </el-select>
+        </el-form-item>
+
+        <el-form-item label="来单语音设置" prop="timbre">
+          <el-select v-model="formData.timbre" placeholder="请选择来单语音">
+            <el-option label="真人语音" :value="0"/>
+            <el-option label="嘀嘀声" :value="3"/>
+            <el-option label="静音" :value="4"/>
+          </el-select>
+        </el-form-item>
+
+        <el-form-item label="打印机音量设置" prop="volume">
+          <el-select v-model="formData.volume" placeholder="请选择打印机音量">
+            <el-option label="大" :value="0"/>
+            <el-option label="中" :value="1"/>
+            <el-option label="小" :value="2"/>
+            <el-option label="关闭" :value="3"/>
+          </el-select>
+        </el-form-item>
+
+        <!--                <el-form-item label="小票模板" prop="mode">-->
+        <!--                    <el-select v-model="formData.mode" placeholder="请选择打印模板">-->
+        <!--                        <el-option label="模板01" :value="1" />-->
+        <!--                    </el-select>-->
+        <!--                </el-form-item>-->
+        <!-- <el-form-item label="排序" prop="sort">
+            <div>
+                <el-input-number v-model="formData.sort" :min="0" :max="9999" />
+                <div class="form-tips">默认为0, 数值越大越排前</div>
+            </div>
+        </el-form-item> -->
+        <el-form-item label="状态" prop="status">
+          <el-switch v-model="formData.status" :active-value="1" :inactive-value="0"/>
+        </el-form-item>
+      </el-form>
+    </popup>
+  </div>
 </template>
 <script lang="ts" setup>
-import type { FormInstance } from 'element-plus'
-import { articleCateEdit } from '@/api/article'
+import type {FormInstance} from 'element-plus'
+import {articleCateEdit} from '@/api/article'
 import Popup from '@/components/popup/index.vue'
 import feedback from '@/utils/feedback'
-import { addPrinter, getPrinterDetail } from '@/api/shop'
+import {addPrinter, getPrinterDetail} from '@/api/shop'
+
 const emit = defineEmits(['success', 'close'])
 const formRef = shallowRef<FormInstance>()
 const popupRef = shallowRef<InstanceType<typeof Popup>>()
 const mode = ref('add')
 const popupTitle = computed(() => {
-    return mode.value == 'edit' ? '编辑' : '新增'
+  return mode.value == 'edit' ? '编辑' : '新增'
 })
 const formData = reactive({
-    id: '',
-    name: '',
-    type: '',
-    finalNumber: '',
-    secret: '',
-    mode: '',
-    status: ''
+  id: '',
+  name: '',
+  type: '1',
+  finalNumber: '',
+  timbre: '1',
+  volume: '2',
+  secret: '',
+  mode: '',
+  status: ''
 })
 
 const formRules = {
-    name: [
-        {
-            required: true,
-            message: '请输入名称',
-            trigger: ['blur']
-        }
-    ],
-    type: [
-        {
-            required: true,
-            message: '请选择类型',
-            trigger: ['blur']
-        }
-    ],
-    finalNumber: [
-        {
-            required: true,
-            message: '请输入终端号',
-            trigger: ['blur']
-        }
-    ],
-    secret: [
-        {
-            required: true,
-            message: '请输入密钥',
-            trigger: ['blur']
-        }
-    ],
-    mode: [
-        {
-            required: true,
-            message: '请选择模板',
-            trigger: ['blur']
-        }
-    ]
+  name: [
+    {
+      required: true,
+      message: '请输入名称',
+      trigger: ['blur']
+    }
+  ],
+  type: [
+    {
+      required: true,
+      message: '请选择类型',
+      trigger: ['blur']
+    }
+  ],
+  finalNumber: [
+    {
+      required: true,
+      message: '请输入终端号',
+      trigger: ['blur']
+    }
+  ],
+  secret: [
+    {
+      required: true,
+      message: '请输入密钥',
+      trigger: ['blur']
+    }
+  ],
+  mode: [
+    {
+      required: true,
+      message: '请选择模板',
+      trigger: ['blur']
+    }
+  ]
 }
 
 const handleSubmit = async () => {
-    await formRef.value?.validate()
-    mode.value == 'edit' ? await articleCateEdit(formData) : await addPrinter(formData)
-    feedback.msgSuccess('操作成功')
-    popupRef.value?.close()
-    emit('success')
+  await formRef.value?.validate()
+  mode.value == 'edit' ? await articleCateEdit(formData) : await addPrinter(formData)
+  feedback.msgSuccess('操作成功')
+  popupRef.value?.close()
+  emit('success')
 }
 
 const open = (type = 'add') => {
-    mode.value = type
-    popupRef.value?.open()
+  mode.value = type
+  popupRef.value?.open()
 }
 
 const setFormData = (data: Record<any, any>) => {
-    for (const key in formData) {
-        if (data[key] != null && data[key] != undefined) {
-            //@ts-ignore
-            formData[key] = data[key]
-        }
+  for (const key in formData) {
+    if (data[key] != null && data[key] != undefined) {
+      //@ts-ignore
+      formData[key] = data[key]
     }
+  }
 }
 
 const getDetail = async (row: Record<string, any>) => {
-    const data = await getPrinterDetail({
-        id: row.id
-    })
-    setFormData(data)
+  const data = await getPrinterDetail({
+    id: row.id
+  })
+  setFormData(data)
 }
 
 const handleClose = () => {
-    emit('close')
+  emit('close')
 }
 
 defineExpose({
-    open,
-    setFormData,
-    getDetail
+  open,
+  setFormData,
+  getDetail
 })
 </script>

+ 156 - 94
src/views/shop/print/index.vue

@@ -1,118 +1,180 @@
 <template>
-    <div>
-        <el-card class="!border-none" shadow="never">
-            <el-alert
-                type="warning"
-                title="温馨提示:小票打印机目前仅支持芯烨云打印机"
-                :closable="false"
-                show-icon
+  <div>
+    <el-card class="!border-none" shadow="never">
+      <el-alert
+          type="warning"
+          title="温馨提示:小票打印机目前仅支持芯烨云打印机"
+          :closable="false"
+          show-icon
+      />
+    </el-card>
+    <el-card class="!border-none mt-4" shadow="never" v-loading="pager.loading">
+      <div>
+        <el-button v-perms="['article:cate:add']" type="primary" @click="handleAdd()">
+          <template #icon>
+            <icon name="el-icon-Plus"/>
+          </template>
+          新增打印机
+        </el-button>
+      </div>
+      <el-table class="mt-4" size="large" :data="pager.lists">
+        <el-table-column type="index" width="55"/>
+        <el-table-column label="打印机名称" prop="name" min-width="120"/>
+        <el-table-column
+            label="设备类型"
+            prop="type"
+            min-width="120"
+            :formatter="(item) => (item.type == '1' ? '芯烨云' : '未知')"
+        />
+        <el-table-column label="终端号" prop="finalNumber" min-width="120"/>
+        <!--                <el-table-column-->
+        <!--                    label="小票模板"-->
+        <!--                    prop="mode"-->
+        <!--                    min-width="120"-->
+        <!--                    :formatter="(item) => (item.mode == '1' ? '模板01' : '未知')"-->
+        <!--                />-->
+        <el-table-column label="来单语音" prop="timbre" min-width="80" :formatter="timbreFormatter"/>
+        <el-table-column label="打印机音量" prop="volume" min-width="80" :formatter="volumeFormatter"/>
+        <el-table-column label="状态" min-width="120">
+          <template #default="{ row }">
+            <el-switch
+                v-perms="['article:cate:change']"
+                v-model="row.status"
+                :active-value="1"
+                :inactive-value="0"
+                @change="changeStatus(row.id)"
             />
-        </el-card>
-        <el-card class="!border-none mt-4" shadow="never" v-loading="pager.loading">
-            <div>
-                <el-button v-perms="['article:cate:add']" type="primary" @click="handleAdd()">
-                    <template #icon>
-                        <icon name="el-icon-Plus" />
-                    </template>
-                    新增打印机
-                </el-button>
-            </div>
-            <el-table class="mt-4" size="large" :data="pager.lists">
-                <el-table-column type="index" width="55" />
-                <el-table-column label="打印机名称" prop="name" min-width="120" />
-                <el-table-column
-                    label="设备类型"
-                    prop="type"
-                    min-width="120"
-                    :formatter="(item) => (item.type == '1' ? '芯烨云' : '未知')"
-                />
-                <el-table-column label="终端号" prop="finalNumber" min-width="120" />
-                <el-table-column
-                    label="小票模板"
-                    prop="mode"
-                    min-width="120"
-                    :formatter="(item) => (item.mode == '1' ? '模板01' : '未知')"
-                />
-                <el-table-column label="状态" min-width="120">
-                    <template #default="{ row }">
-                        <el-switch
-                            v-perms="['article:cate:change']"
-                            v-model="row.status"
-                            :active-value="1"
-                            :inactive-value="0"
-                            @change="changeStatus(row.id)"
-                        />
-                    </template>
-                </el-table-column>
-                <el-table-column label="操作" width="120" fixed="right">
-                    <template #default="{ row }">
-                        <el-button
-                            v-perms="['article:cate:edit']"
-                            type="primary"
-                            link
-                            @click="handleEdit(row)"
-                        >
-                            编辑
-                        </el-button>
-                        <el-button
-                            v-perms="['article:cate:del']"
-                            type="danger"
-                            link
-                            @click="handleDelete(row.id)"
-                        >
-                            删除
-                        </el-button>
-                    </template>
-                </el-table-column>
-            </el-table>
-            <div class="flex justify-end mt-4">
-                <pagination v-model="pager" @change="getLists" />
-            </div>
-        </el-card>
-        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
-    </div>
+          </template>
+        </el-table-column>
+        <el-table-column label="操作" width="120" fixed="right">
+          <template #default="{ row }">
+            <el-button
+                v-perms="['article:cate:edit']"
+                type="primary"
+                link
+                @click="handleEdit(row)"
+            >
+              编辑
+            </el-button>
+            <el-button
+                v-perms="['article:cate:edit']"
+                type="primary"
+                link
+                @click="handlePrint(row)"
+            >
+              测试打印机
+            </el-button>
+            <el-button
+                v-perms="['article:cate:del']"
+                type="danger"
+                link
+                @click="handleDelete(row.id)"
+            >
+              删除
+            </el-button>
+          </template>
+        </el-table-column>
+      </el-table>
+      <div class="flex justify-end mt-4">
+        <pagination v-model="pager" @change="getLists"/>
+      </div>
+    </el-card>
+    <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false"/>
+  </div>
 </template>
 <script lang="ts" setup>
-import { articleCateDelete, articleCateStatus } from '@/api/article'
-import { usePaging } from '@/hooks/usePaging'
+import {articleCateDelete, articleCateStatus} from '@/api/article'
+import {usePaging} from '@/hooks/usePaging'
 import feedback from '@/utils/feedback'
 import EditPopup from './edit.vue'
-import { getPrinterList } from '@/api/shop'
+import {getPrinterList} from '@/api/shop'
+import {timeFormat} from '@/utils/util'
+
 const editRef = shallowRef<InstanceType<typeof EditPopup>>()
 const showEdit = ref(false)
 
-const { pager, getLists } = usePaging({
-    fetchFun: getPrinterList
+const {pager, getLists} = usePaging({
+  fetchFun: getPrinterList
 })
 const handleAdd = async () => {
-    showEdit.value = true
-    await nextTick()
-    editRef.value?.open('add')
+  showEdit.value = true
+  await nextTick()
+  editRef.value?.open('add')
 }
 
 const handleEdit = async (data: any) => {
-    showEdit.value = true
-    await nextTick()
-    editRef.value?.open('edit')
-    editRef.value?.getDetail(data)
+  showEdit.value = true
+  await nextTick()
+  editRef.value?.open('edit')
+  editRef.value?.getDetail(data)
+}
+
+const timbreFormatter = (row: any) => {
+  if (row.timbre == 0) {
+    return '真人语音'
+  } else if (row.timbre == 3) {
+    return '嘀嘀声'
+  } else {
+    return '静音'
+  }
+}
+const volumeFormatter = (row: any) => {
+  if (row.volume == 0) {
+    return '大'
+  } else if (row.volume == 1) {
+    return '中'
+  } else if (row.volume == 2) {
+    return '小'
+  } else {
+    return '关闭'
+  }
 }
 
 const handleDelete = async (id: number) => {
-    await feedback.confirm('确定要删除?')
-    await articleCateDelete({ id })
-    feedback.msgSuccess('删除成功')
-    getLists()
+  await feedback.confirm('确定要删除?')
+  await articleCateDelete({id})
+  feedback.msgSuccess('删除成功')
+  getLists()
 }
 
 const changeStatus = async (id: number) => {
-    try {
-        await articleCateStatus({ id })
-        feedback.msgSuccess('修改成功')
-        getLists()
-    } catch (error) {
-        getLists()
-    }
+  try {
+    await articleCateStatus({id})
+    feedback.msgSuccess('修改成功')
+    getLists()
+  } catch (error) {
+    getLists()
+  }
 }
 
+const handlePrint = async (row: any) => {
+  const res = await feedback.request({
+    url: '/api/printer/print',
+    method: 'post',
+    data: {
+      id: row.id,
+      brandId: row.brandId,
+      houseId: row.houseId,
+      orderNo: '123456789987654321',
+      deskNo: '大厅',
+      orderSource: '扫码支付',
+      orderTime: timeFormat(Date.now(), 'yyyy年mm月dd日 hh时MM分'),
+      remark: '测试打印机',
+      userNum: '4',
+      amount: '30',
+      discount: '10',
+      orderDishes: [
+        {'title': '测试菜品1', 'num': '1', 'summary': '10'},
+        {'title': '测试菜品2', 'num': '1', 'summary': '18'},
+        {'title': '测试菜品3', 'num': '1', 'summary': '12'}
+      ]
+    }
+  })
+  if (res.code == 200) {
+    feedback.msgSuccess('测试打印成功')
+  } else {
+    feedback.msgError('测试打印失败')
+  }
+}
 getLists()
 </script>