word.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!-- 播放文字 -->
  2. <template>
  3. <view id="word">
  4. <view class="title-p">广播内容</view>
  5. <textarea placeholder="请输入广播内容" v-model="text"></textarea>
  6. <view class="radio-box">
  7. <view class="radio-title">播报方式</view>
  8. <radio-group @change="radioChange" class="radio-max-button">
  9. <label class="radio-button" v-for="(item, index) in items" :key="item.value">
  10. <radio :value="item.value" color="#007AFF" :checked="index === current" />{{item.name}}
  11. </label>
  12. </radio-group>
  13. </view>
  14. <view class="button-view" @click="voiceButton">确定</view>
  15. </view>
  16. </template>
  17. <script>
  18. import { voice } from '@/api/index.js'
  19. export default {
  20. data() {
  21. return {
  22. itemData:{},
  23. text:"",
  24. type:"",
  25. items:[
  26. {
  27. name:"文字",
  28. value:"1"
  29. },
  30. {
  31. name:"音频",
  32. value:"2"
  33. },
  34. ]
  35. }
  36. },
  37. onLoad(option) {
  38. this.itemData = JSON.parse(decodeURIComponent(option.item));
  39. },
  40. methods: {
  41. radioChange(e){
  42. console.log("e",e)
  43. this.type = e.detail.value;
  44. },
  45. voiceButton(){
  46. let self = this;
  47. if(!this.text){
  48. uni.showToast({
  49. title: '请输入广播内容',
  50. icon:"none",
  51. mask:true,
  52. duration: 2000
  53. });
  54. return
  55. }
  56. if(!this.type){
  57. uni.showToast({
  58. title: '请选择播报方式',
  59. icon:"none",
  60. mask:true,
  61. duration: 2000
  62. });
  63. return
  64. }
  65. uni.showModal({
  66. // title: '确认要退出吗?',
  67. content: '确认播放吗?',
  68. cancelColor:"#999",
  69. confirmColor:"#0183FA",
  70. success: function (res) {
  71. if (res.confirm) {
  72. self.voice();
  73. console.log('用户点击确定');
  74. } else if (res.cancel) {
  75. console.log('用户点击取消');
  76. }
  77. }
  78. });
  79. },
  80. //播放
  81. async voice(){
  82. let obj = {
  83. txt:this.text,
  84. type:this.type
  85. };
  86. const {data} = await voice(this.itemData.id,obj);
  87. if(data.code == 200){
  88. uni.showToast({
  89. title: '播放成功',
  90. icon:"none",
  91. mask:true,
  92. duration: 2000
  93. });
  94. setTimeout(function(){
  95. uni.navigateBack();
  96. },2000);
  97. }
  98. },
  99. }
  100. }
  101. </script>
  102. <style lang="stylus" scoped>
  103. #word{
  104. height:100%;
  105. background #fff
  106. overflow hidden
  107. .title-p{
  108. font-size:28rpx;
  109. margin:20rpx 0 20rpx 20rpx;
  110. line-height:60rpx;
  111. }
  112. textarea{
  113. width:670rpx;
  114. height:200rpx;
  115. margin:20rpx 20rpx 0;
  116. font-size:26rpx;
  117. border: 1rpx solid #E0E0E0;
  118. border-radius:10rpx;
  119. padding:20rpx;
  120. }
  121. .radio-box{
  122. font-size:26rpx;
  123. .radio-title{
  124. font-size:28rpx;
  125. margin:20rpx 0 20rpx 20rpx;
  126. line-height:60rpx;
  127. }
  128. .radio-max-button{
  129. display flex
  130. margin:0 100rpx;
  131. .radio-button{
  132. flex:1;
  133. margin-left:75rpx;
  134. font-size:26rpx;
  135. }
  136. }
  137. }
  138. .button-view{
  139. width: 600rpx;
  140. height: 80rpx;
  141. background: #0183FA;
  142. border-radius: 20rpx;
  143. font-size:30rpx;
  144. line-height:80rpx;
  145. text-align center;
  146. color: #fff;
  147. margin:90rpx auto;
  148. }
  149. }
  150. </style>